donghongbz 2011-10-12
这个方法的行为表现与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> 本文实例讲述了jquery trigger实现联动的方法。分享给大家供大家参考,具体如下:。<input type="button" value="设置成湖北襄阳" onclick="test()&q