這段代碼什么意思
?$("button:last").click(function() {
? ? ? ? $("button:first").trigger('click','last');
? ? });
這里面的last是什么?參數?怎么傳遞啊?還有下面那個bottonname是啥?
?$("button:last").click(function() {
? ? ? ? $("button:first").trigger('click','last');
? ? });
這里面的last是什么?參數?怎么傳遞啊?還有下面那個bottonname是啥?
2016-08-05
舉報
2017-01-09
?//點擊更新次數
? ? $("button:first").click(function(event,bottonName) {
? ? ? ? bottonName = bottonName || 'first';
? ? ? ? update($("span:first"),$("span:last"),bottonName); ? ? ?//1號位
? ? });
? ? //通過自定義事件調用,更新次數
? ? $("button:last").click(function() {
? ? ? ? $("button:first").trigger('click','last');
? ? });
? ? function update(first,last,bottonName) { ? ? ? ? ? ? ? ? ? ? ? ? //2號位
? ? ? ? first.text(bottonName);
? ? ? ? var n = parseInt(last.text(), 10);
? ? ? ? last.text(n + 1);
? ? }
update很誤導人,1號位的update不是原生函數,它所表示的實際上就是后文咱們自定義的2號位的update函數。
然后就可以清楚看到,三個參數是對應的。1號位的update()是對后文2號位函數的主動調用。而trigger()又會調用click函數,所以無論點哪個按鈕,2號位函數都會起作用。
建議大家把update都改成別的名字再試試就懂了。一直覺得教程不該用這種“疑似原生函數名”,容易混淆,我們萌新經常栽在這里。
2016-12-09
我也看的暈的很,last怎么傳到里面的?
2016-08-15
2016-08-12
bottonName?=?bottonName?||?'first';?
所以上面這段話,可以怎么解釋呢
這篇看了有點懵懂阿~~~
2016-08-12
借問,||這符號是什么意思啊
2016-08-05
看課程評論里的這段解釋:重點在 $("button:first").trigger('click','last');直接引用了第一個按鈕的事件,'last'傳給 bottonName做參數,所以點擊第二個按鈕,bottonName =“last”,接下來就是update()函數了,update(firstq,lastq,bottonName) ? 在第一個按鈕點擊事件時first,last,已經傳入參數$("span:first"),$("span:last"),也就是顯示內容的首位名稱和 第二位數字,接下來update()函數里面把first.text()根據點擊改括號里面內容,last或first數字同理。
bottonName是下面定義的update函數的參數名