JQUERY triggerHandler 与trigger的区别
这个方法的行为表现与trigger类似,但有以下三个主要区别:
* 第一,他不会触发浏览器默认事件。
* 第二,只触发jQuery对象集合中第一个元素的事件处理函数。
* 第三,这个方法的返回的是事件处理函数的返回值,而不是据有可链性的jQuery对象。此外,如果最开始的jQuery对象集合为空,则这个方法返回 undefined 。
<script>
$(document).ready(function(){
//trigger:触发系统的click事件 
$("#old").click(function(){
$("input").trigger("focus");
});
//triggerHandler:不触发系统的click事件 
$("#new").click(function(){
$("input").triggerHandler("focus");
});
$("input").focus(function(){
$("<span>Focused!</span>").appendTo("body").fadeOut(1000);
});
});
</script>
</head>
<body>
<input type="button"/>
<button id="old">.trigger("focus")</button>
<button id="new">.triggerHandler("focus")</button><br/><br/>
<input type="text" value="To Be Focused"/>
</body> 相关推荐
  Chriswang    2020-04-30  
   donghongbz    2020-01-18  
   leonranri    2016-12-09  
   workflow    2013-08-15  
   stingfire    2012-05-16  
   itwxming    2015-09-02  
   周健华    2019-06-28  
   去山中嘘嘘    2015-01-21  
   Awara    2019-06-27  
   小肖    2014-05-19  
   mxcsdn    2010-10-20  
   adeyi    2019-06-21  
   咸鱼    2012-10-28  
   greensomnuss    2012-10-09  
   Gcalolin    2019-06-20  
   愚盦    2011-05-24  
   每天积累一点点    2011-03-08  
   Lucianoesu    2018-10-27  
   MySQL    2018-09-24  
 