<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>设计器</title>
<script name="systemJs" type="text/javascript" src="../../zhuant-design/js/jquery-1.11.3.min.js"></script>
</head>
<body>
<button id="old">.trigger("focus")</button>
<button id="new">.triggerHandler("focus")</button><br/><br/>
<input type="text" value="To Be Focused"/>
<br>
<span id="content">这是内容</span>
<ul>
<li>test1</li>
<li>test1</li>
<li>test1</li>
</ul>
<script type="text/javascript">
$("#old").click(function(){
$("input").trigger("focus");
});
$("#new").click(function(){
$("input").triggerHandler("focus");
});
$("input").focus(function(){
$("<span>Focused!</span>").appendTo("body").fadeOut(1000);
});
$("li").click(function(){
$("#content").triggerHandler("getContent");
});
$("#content").bind("getContent",function(){
alert($(this).text());
});
</script>
</body>
</html>
关于jQuery中的trigger和triggerHandler方法的使用
最新推荐文章于 2023-07-27 09:01:50 发布