這裏很新穎,對於基本問題表示歉意。試圖完成奧丁項目的構建計算器的挑戰(http://www.theodinproject.com/javascript-and-jquery/on-screen-calculator)如何顯示和存儲按鈕值?
並努力使數字出現後,他們被點擊。另外,如何將該值存儲在一個變量或數組中,然後用於以後的計算?
這裏是我JS的摘錄:
$(".numbers").on("click", function() {
$+(this).text()
;});
而我的HTML(注意我用的jsfiddle,因此缺乏HTML打開和關閉標籤等:
<script src="jquery-1.11.3.min.js"></script>
<div class="numbers">
<button type="button">0</button>
<button type="button">1</button>
<button type="button">2</button>
<button type="button">3</button>
<button type="button">4</button>
<button type="button">5</button>
<button type="button">6</button>
<button type="button">7</button>
<button type="button">8</button>
<button type="button">9</button>
</div>
<div class = "operators">
<button type="button">+</button>
<button type="button">-</button>
<button type="button">*</button>
<button type="button">/</button>
<button type="button">=</button>
<button type="button">clear</button>
</div>
如果你使用jsfiddle,並且你已經在那裏設置了一個隔離問題的演示,那麼鏈接到jsfiddle本身就非常好 –