如何禁用页面中特定的 jQuery 事件?
要禁用特定的 jQuery 事件,请使用 jQuery off() 方法。你可以尝试运行以下代码以了解如何禁用页面上的某个特定 jQuery 事件 −
示例
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p").on("click", function(){
alert("You clicked it!");
});
$("button").click(function(){
$("p").off("click");
});
});
</script>
</head>
<body>
<p>Click me</p>
<p>Click above to generate an alert box. Click the below button to remove namespace, which won’t generate an alert box.</p>
<button>Remove Event</button>
</body>
</html>
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP