如何停用頁面中特定的 jQuery 事件?
要停用特定的 jQuery 事件,請使用 jQuery off() 方法。你可以嘗試執行以下程式碼以瞭解如何停用頁面上的某個特定 jQuery 事件 −
示例
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/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