Home  >  Article  >  Web Front-end  >  Example introduction to the difference between jquery's trigger and triggerHandler_jquery

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

WBOY
WBOYOriginal
2016-05-16 16:51:51750browse

Both trigger and triggerHandler simulate the occurrence of events. Use specific cases to describe the differences

Copy the code The code is as follows:




test








<script> <br>$( document ).ready(function() { <br> $("input[type='checkbox']").bind("click",function(){ <br>$("#test").val("www.baidu.com"); <br>} ); <br>}); <br><br>function bntClick(){ <br>$("input[type='checkbox']").trigger("click"); <br>} <br> </script>


When you click the checkbox, check the checkbox and assign input[type='text'] to www.baidu.com

When input[type='button'] is clicked, the same thing as clicking checkbox will happen

When trigger is replaced with triggerHandler, when input[type='button'] is clicked, only Assigning a value to input[type='text'] without checking the checkbox

triggerHandler prevents the default behavior of the element bound to the event
Statement:
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