Home > Web Front-end > JS Tutorial > Sharing experience on using triggerHandler() in jQuery

Sharing experience on using triggerHandler() in jQuery

巴扎黑
Release: 2017-06-25 14:26:53
Original
1566 people have browsed it

This article mainly introduces the usage of triggerHandler() method in jQuery. The example analyzes the function and definition of triggerHandler() method and the usage skills of triggering the specified event type of selected elements. Friends in need You can refer to the following

The examples in this article describe the usage of the triggerHandler() method in jQuery. Share it with everyone for your reference. The specific analysis is as follows:

This method triggers the specified event type of the selected element.
It can be seen from the above definition that this method is very similar to the trigger() method in function, but there is still a huge difference. The following are the main differences:

1. This method will not trigger the browser default event.
2. This method triggers the event processing function of the first element in the jQuery object collection and does not generate event bubbling.
3. This method returns the return value of the event processing function, rather than the chainable jQuery object.

Grammar structure:

The code is as follows:

$(selector).triggerHandler(event,[param1,param2,... ])

Parameter list:

##Parameter Description
event Specifies the event type to be triggered by the specified element.
param Optional. Additional parameters passed to the event handler.

Example code:

The code is as follows:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.jb51.net/" />
<title>脚本之家</title>
<style type="text/css">
p{
  width:200px;
  height:200px;
  border:1px solid blue;
}
</style>
<script type="text/
javascript
" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript"> 
$(
document
).ready(function(){ 
  $("p").click(function(){ 
    $("p").append("脚本之家"); 
  }); 
  $("button").click(function(){ 
    $("p").triggerHandler("click"); 
  }) 
}) 
</script>
</head>
<body>
<p></p>
<button>查看效果</button>
</body>
</html>
Copy after login


The above is the detailed content of Sharing experience on using triggerHandler() in jQuery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template