jQuery鼠标键盘表单事件大全

本文介绍了一个使用jQuery实现的事件监听示例,包括鼠标点击、双击、覆盖、移入和移出等事件,以及键盘按键、焦点获得和失去、表单提交等交互事件的处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!DOCTYPE html>
<html>
<head>
    <title>jquery事件监听</title>
    <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script type="text/javascript">
        $(function(){
            var msg = $('#msg');
            //鼠标点击事件
            $('#div1').click(function(){
                msg.html('1被点击了');
                msg.fadeIn(1000);
                msg.fadeOut(1000);
            });
            //鼠标双击事件
            $('#div2').dblclick(function(){
                msg.html('2被双击了');
                msg.fadeIn(1000);
                msg.fadeOut(1000);
            });
            //鼠标覆盖事件
            $('#div3').mouseover(function(){
                msg.html('鼠标在3上面');
                msg.fadeIn(1000);
                msg.fadeOut(1000);
            });
            //鼠标移入事件
            $('#div4').mouseenter(function(){
                msg.html('鼠标移入了4');
                msg.fadeIn(1000);
                msg.fadeOut(1000);
            });
            //鼠标移出事件
            $('#div4').mouseleave(function(){
                msg.html('鼠标移出了4');
                msg.fadeIn(1000);
                msg.fadeOut(1000);
            });
            //鼠标按下事件
            $('#div5').mousedown(function(){
                msg.html('鼠标在5按下了');
                msg.fadeIn(1000);
                msg.fadeOut(1000);
            });
            //鼠标松开事件
            $('#div5').mouseup(function(){
                msg.html('鼠标在5松开了');
                msg.fadeIn(1000);
                msg.fadeOut(1000);
            });

            $('#input1').keydown(function(){
                msg.html('在input1按下键盘!');
                msg.fadeIn(1000);
                msg.fadeOut(1000);
            });
            $('#input1').keyup(function(){
                msg.html('在input1松开键盘!');
                msg.fadeIn(1000);
                msg.fadeOut(1000);
            });

            $('#input1').focus(function(){
                msg.html('input1得到了焦点!');
                msg.fadeIn(1000);
                msg.fadeOut(1000);
            });
            $('#input1').blur(function(){
                msg.html('input1失去了焦点!');
                msg.fadeIn(1000);
                msg.fadeOut(1000);
            });

            $('#input2').change(function(){
                msg.html('input2的内容改变了!并失去了焦点');
                msg.fadeIn(1000);
                msg.fadeOut(1000);
            });

            $('#mainForm').submit(function(event) {
                msg.html('表单内容提交!');
                msg.fadeIn(1000);
                msg.fadeOut(1000);
            });
        });
    </script>
    <style type="text/css">
        .div1{
            height: 30px;
            width: 30px;
            background: pink;
            display: inline-block;
            margin: 5px;
        }
    </style>
</head>
<body>
    <div class="div1" id="div1">1</div>
    <div class="div1" id="div2">2</div>
    <div class="div1" id="div3">3</div>
    <div class="div1" id="div4">4</div>
    <div class="div1" id="div5">5</div>
    <form id="mainForm" action="#">
        1:<input type="text" id="input1"/><br>
        2:<input type="text" id="input2"/><br>
        <input type="submit" name="submit">
    </form>
    <div id="msg" style="display:none"></div>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值