<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
<style type="text/css">
.left div, .right div {
width: 500px;
height: 50px;
padding: 5px;
margin: 5px;
float: left;
border: 1px solid #ccc;
}
.left div {
background: #bbffaa;
}
.right div {
background: yellow;
}
</style>
</head>
<body>
<h2>自定义事件trigger</h2>
<div class="left">
<div><span></span><span>0</span>点击次数</div>
<button>直接点击</button>
<button>通过自定义点击</button>
</div>
<script type="text/javascript">
//点击更新次数
$("button:first").click(function(event,bottonName){
bottonName = bottonName || 'first';
update($("span:first"),$("apan:last"),bottonName);
});
//通过自定义事件调用,更新次数
$("button:last").click(function(){
$("button:first").trigger('click','last');
});
function update(first,last,bottonName){
first.text(bottonName);
var n = parseInt(last.text(),10);
last.text(n + 1);
}
</script>
</body>
</html>