2個疑問??
? 1.
? ? ?
//點擊更新次數
? ? $("button:first").click(function(event,bottonName) {
? ? ? ? bottonName = bottonName || 'first';
? ? ? ? update($("span:first"),$("span: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);
? ? }
$("button:first").trigger('click','last'); ?里面的'last'為什么是傳給?bottonName,而不是function update(first,last,bottonName)里的last?
2.去掉代碼
? ? ?
$("button:first").click(function(event,bottonName) {
? ? ? ? bottonName = bottonName || 'first';
? ? ? ? update($("span:first"),$("span:last"),bottonName);
? ? });
為什么效果不對?
2016-08-20
1.這個last是他自己定義的參數,對應function中的(bottomName)。而update里的last,其實是 $("span:last");
2.去掉代碼之后,bottonNam 這個參數是空的。而且update函數都不存在了,怎么調用?
2016-08-31
感覺$("button:first").trigger('click','last'); 里面的last對應的是? $("button:first").click(function(event,bottonName) 里面function的bottonName,不知道我說的對不對
2016-08-20
trigger是觸發被選中元素指定的事件類型
2016-08-20
看看一個trigger方法的定義