哪些 jQuery 事件不冒泡?
某些 jQuery 事件不會冒泡,例如 mouseenter 不會冒泡。我們來看一個這樣的事件示例。
示例
你可以嘗試執行以下程式碼,瞭解如何使用不冒泡的 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").mouseenter(function(){ $("p").css("background-color", "red"); }); $("p").mouseleave(function(){ $("p").css("background-color", "blue"); }); }); </script> </head> <body> <p>Demo Text - Keep the mouse pointer here.</p> </body> </html>
廣告