jquery事件操作

原创2018-11-16 18:52:5591
摘要:<!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <title>jQuery事件操作</ti
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>jQuery事件操作</title>
    <script src="jquery-3.3.1.min.js"></script>
    <style>
        div{
            margin: 0 auto;
            text-align: center;
        }

        #show{
            width: 100px;
            height: 100px;
            background-color:seashell;
        }
    button{
        margin-top:50px;
    }
    </style>
</head>
<body>
<div>
    <div id="show">

    </div>
    <input type="text" value="请输入账号">
    <button type="button" id="cz" value="操作">操作</button><br>


    <span> 鼠标放上来会变的</span>
    <div id="sbwz">


    </div>
</div>


<script>
    $(document).ready(function () {//就绪函数
 // alert("1111");
        //点击事件
 $('button').click(function () {
            var a = $('button').val();
            //alert(a);
 if (a == '操作') {
                $('#show').css('background', 'red');
                $('#cz').text("red").attr('value', 'red');
            } else {
                $('#show').css('background', 'pink');
                $('#cz').text("操作").attr('value', '操作');
            }
        })

        //获取焦点
 $('input').focus(function () {
                $('input').attr('value',"");
        });

        //失去焦点
 $('input').blur(function () {
            var a = $('input').val();
            if(a == ""){
                $('input').attr('value','请输入账号')
            }
        });

        //鼠标移上
 $('span').mouseover(function () {
         $('span').css('background','red');
       });
        //鼠标离开
 $('span').mouseleave(function () {
            $('span').css('background','yellow');
        })

        //取鼠标位置
 $(document).mousemove(function (a) {
            //alert(a.pageX);
 $('#sbwz').text('X:'+a.pageX+'---'+'Y:'+a.pageY);

        })
        })
</script>

</body>
</html>

总结:事件关键函数不太熟悉。如果使用需要直接去找。。。。还需要加强记忆

发布手记

热门词条