如何暫時禁止 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>
廣告