如何禁用页面上的特定jQuery事件?
要禁用特定的jQuery事件,请使用jQueryoff()
方法。您可以尝试运行以下代码以了解如何在页面上禁用特定的jQuery事件-
示例
<!DOCTYPE html> <html> <head> <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("p").on("click", function(){ alert("您点击了!"); }); $("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>