Home > Web Front-end > JS Tutorial > body text

Example introduction to the difference between jquery's trigger and triggerHandler

巴扎黑
Release: 2017-06-25 13:59:17
Original
1074 people have browsed it

This article mainly introduces the difference between jquery's trigger and triggerHandler. Friends in need can refer to

trigger and triggerHandler both simulate event. Use a specific case to describe the difference

The code is as follows:

<html lang="en"> 
<head> 
<meta charset="utf-8"> 
<title>test</title> 
<script src="http://code.jquery.com/jquery-1.10.2.js"></script> 
</head> 
<body> 
<input type="checkbox" /> 
<input type="text" id="test"/> 
<input type="button" value="button" id="bnt" 
onclick
="bntClick()"/> 
</body> 
<script> 
$( 
document
 ).ready(function() { 
$("input[type=&#39;checkbox&#39;]").bind("click",function(){ 
$("#test").val("www.baidu.com"); 
}); 
}); 
function bntClick(){ 
$("input[type=&#39;checkbox&#39;]").trigger("click"); 
} 
</script> 
</html>
Copy after login

When the checkbox is clicked, the checkbox is checked and input[type='text'] is assigned the value www.baidu. com
When input[type='button'] is clicked, the same thing as clicking checkbox will happen.
When the trigger is replaced with triggerHandler, when input[type='button'] is clicked, only input[type='text'] is assigned a value without checking the checkbox
triggerHandler prevents the default behavior of the element bound to the event

The above is the detailed content of Example introduction to the difference between jquery's trigger and triggerHandler. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!