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>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号