博客列表 > jQuery中的事件注册与删除: on()和off()方法的使用

jQuery中的事件注册与删除: on()和off()方法的使用

phpcn_u68463的博客
phpcn_u68463的博客原创
2017年12月24日 18:52:22530浏览

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title></title>

<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js" type="text/javascript" charset="utf-8"></script>

<style type="text/css">

div{

width: 200px;height: 200px;background: red;

}

</style>

</head>

<body>

<div id=""></div>

</body>

</html>

2017-12-24_192928.png

<script type="text/javascript">

$('div').on('click',function(){

// $(this).css('background','blueviolet')

// $(this)[0].style.background = 'yellow'

$(this).get(0).style.background = 'yellow'

}).on('mouseenter',function(){

alert(555)

}).on('mouseleave',function(){

alert(888)

})


$('div').off('mouseenter')

</script>



声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议