要使用多个事件触发相同的功能,请使用具有多个事件的jQueryon()
方法,例如click,dblclick,鼠标进入,鼠标离开,悬停等。
您可以尝试运行以下代码,以了解如何对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({ mouseenter: function(){ $(this).css("background-color", "gray"); }, mouseleave: function(){ $(this).css("background-color", "red"); }, dblclick: function(){ $(this).css("background-color", "yellow"); } }); }); </script> </head> <body> <p>Click, double click and move the mouse pointer.</p> </body> </html>