<!DOCTYPE html><html><head>? ? <meta http-equiv="Content-type" content="text/html; charset=utf-8" />? ? <title></title>? ? <style>? ? .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>? ? <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script></head><body>? ? <h2>自定義事件trigger</h2>? ? <div class="left">? ? ? ? <div><span></span><span>0</span>點擊次數(shù)</div>? ? ? ? <button>直接點擊</button>? ? ? ? <button>通過自定義點擊</button>? ? </div>? ? <script type="text/javascript">? ? //點擊更新次數(shù)? ? $("button:first").click(function(event,bottonName) {? ? ? ? bottonName = bottonName || 'first';? ? ? ? update($("span:first"),$("span:last"),bottonName);? ? });? ? //通過自定義事件調用,更新次數(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>
誰能解釋:trigger事件的例子
qyy2499760117_葉子
2016-06-08 14:43:42