The method for setting click events in jquery is click(); this method is used to set a click event to occur when an element is clicked. When the mouse pointer stays over the element and the left button is clicked, the click event will be triggered or Specifies the function to be run when a click event occurs. The syntax is "element object.click (run function)".
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
The method for clicking events in jquery is click() method
When the element is clicked , a click event occurs.
A click occurs when the mouse pointer stays over an element, and then the left mouse button is pressed and released.
The click() method triggers a click event, or specifies a function to run when a click event occurs.
Trigger click event
$(selector).click()
Bind function to click event
$(selector).click(function)
function Optional. Specifies a function to run when a click event occurs.
The example is as follows:
<html> <head> <script type="text/javascript" src="/jquery/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("p").slideToggle(); }); $("p").dblclick(function(){ $("button").click(); }); }); </script> </head> <body> <button>点击这里进行切换</button> <p>双击本段落会触发上面这个按钮的 click 事件。</p> </body> </html>
Output result:
##Related video tutorial recommendation:The above is the detailed content of What is the method to set click event in jquery. For more information, please follow other related articles on the PHP Chinese website!