博客列表 >jquery的事件绑定与解绑

jquery的事件绑定与解绑

yestrue的博客
yestrue的博客原创
2017年12月20日 02:29:53847浏览

jquery中事件绑定用on(),解绑事件用off();

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jquery的事件绑定与解绑</title>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<style>
.box{
width: 200px;
height: 200px;
background-color: orange;
border-radius: 100px;
line-height: 200px;
text-align: center;
}
</style>
</head>
<body>
<div>点击变大</div>
<button>禁用点击事件</button>
<script>
$('.box').on('click',function(){
$(this).css({
width: '300px',
height: '300px',
borderRadius:'150px',
lineHeight:'300px'
});
});
$('button').on('click',function(){
$('.box').off('click');
});
</script>
</body>
</html>


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