如何暫時抑制 jQuery 事件處理?
要暫時抑制 jQuery 事件處理,請向元素新增一個類,以便阻止進一步執行程式碼。
示例
你可以嘗試執行以下程式碼來學習如何抑制 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(){
$(element).click(function(e) {
e.preventDefault();
// Check for fired class
if ($(this).hasClass('fired') == false) {
// Add fired class
$(element).addClass('fired');
// Remove fired class
$(element).removeClass('fired');
}
});
});
</script>
<style>
.fired {
font-size: 25px;
color: green;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p class="fired">This is a paragraph.</p>
<p class="fired">This is second paragraph.</p>
</body>
</html>
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP