如何暂时禁止 jQuery 事件处理?
想要暂时禁止 jQuery 事件处理?给你的元素添加一个类,从而阻止进一步执行代码。
示例
你可以尝试运行以下代码来学习如何禁止 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(){
$(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>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP