jQuery事件

jQuery 事件

鼠标事件

1 jQuery click事件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>jQuery 事件</title>
</head>
<body>
<p>点击这个段落。</p>
</body>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
    //click() 方法是当按钮点击事件被触发时会调用一个函数
    //单击 <p> 元素时警报文本
    //alert n. 警报,警示;警戒,警惕;(电子设备的)提示信号;警戒期
    $(document).ready(function(){
        $("p").click(function(){
            alert("段落被点击了。");
        });
    });
    /*
    定义和用法
    当单击元素时,发生 click 事件。
    click() 方法触发 click 事件,或规定当发生 click 事件时运行的函数。
     */
</script>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title></title>
</head>
<body>
<p>点击这个段落,使其消失。</p>
</body>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("p").click(function(){
    $(this).fadeOut();
  });
});
</script>
</html>

参考:https://www.runoob.com/try/try.php?filename=tryjquery_event_click
2.jQuery dblclick() 事件

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title></title>
</head>
<body>
<p>双击这个段落。</p>
</body>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("p").dblclick(function(){
   alert("这个段落被双击。");
  });
});
</script>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title></title>
</head>
<body>

<button>触发 p 元素的 dblclick 事件</button>
<p ondblclick="alert('dblclick 事件被触发')">这是一个段落。</p>

</body>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").dblclick();
  });
});
</script>

</html>

参考:https://www.runoob.com/jquery/event-dblclick.html
3.jQuery mouseenter() 方法

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>

<p>鼠标移动到该段落。</p>

</body>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("p").mouseenter(function(){
    $("p").css("background-color","yellow");
  });
  $("p").mouseleave(function(){
    $("p").css("background-color","lightgray");
  });
});
</script>

</html>

参考:https://www.runoob.com/jquery/event-mouseenter.html
4.jQuery hover() 方法

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>

<p>鼠标移动到该段落。</p>

</body>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("p").hover(function(){
    $("p").css("background-color","yellow");
    },function(){
    $("p").css("background-color","pink");
  });
});
</script>
</html>

参考:https://www.runoob.com/jquery/event-hover.html
在这里插入图片描述参考:https://www.runoob.com/jquery/jquery-events.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weixin_51297617

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值