<!doctype?html>
<html>
<head>
<meta?charset="utf-8">
<title>無標(biāo)題文檔</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>點(diǎn)擊次數(shù)</div>
????<button>直接點(diǎn)擊</button>
????<button>通過自定義點(diǎn)擊</button>
</div>
<script?type="text/javascript">
//點(diǎn)擊更新次數(shù)
$("button:first").click(function(event,bottonName){
bottonName?=?bottonName?||?'first';
update($("span:first"),$("apan:last"),bottonName);
});
//通過自定義事件調(diào)用,更新次數(shù)
$("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>
2017-10-17
第36行寫錯(cuò)了update($("span:first"),$("apan:last"),bottonName); ? ? span:last 你寫成了apan:last