有沒有誰可以詳細的說一下每局是什么意思嗎? 看半天看不太懂
? ? $("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);
? ? }
2017-08-17
?第一大段代碼$("button:first").click(function(event,bottonName)你只要點擊按鈕1就會觸發點擊事件.click(function(event,bottonName)由于一開始的bottonName這個參數是不存在的所以bottonName=bottonName|| 'first';這個語句的返回值是'first'? 然后再調用update這個函數 update($("span:first"),$("span:last"),‘first’);? 解釋完第一段代碼的含義我們來看第三段代碼 用得出的參數去替換第三段代碼函數的三個參數可得 $("span:first").text('first')??????? var n=parseInt($("span:last").text(), 10);?????? $("span:last").text(n+1);??????? 你看原文第31行的代碼 原文結構體中定義著<div><span></span><span>0</span>點擊次數</div>?? 所以點擊按鈕一執行一次這三個語句后?? <div><span>first</span><span>1</span>點擊次數</div>? 按照這個道理你可以去看第二段代碼的應用