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

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

WBOY
Release: 2016-05-16 16:51:51
Original
749 people have browsed it

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
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