我正在試圖製作JavaScript計算器。我想在JavaScript中創建簡單的加法函數,但不知道如何構建該邏輯,需要某人的幫助,並且在我的代碼中有一個輸入文本字段。如何在一個輸入框中在javascript中創建附加功能
代碼包含輸入按鈕,這是數字現在我需要幫助。那麼我如何在JavaScript中添加函數呢?
function plus()
{
var textInputval=0;
var textInputval1=2;
var temp=0;
textInputval = parseInt(document.getElementById('new').value);
textInputval1 = parseInt(document.getElementById('new').value);
temp = textInputval + textInputval1;
console.log(textInputval);
console.log(textInputval1);
}
<div id = "cal-container">
<form name="calculator">
<input type="text" name="answer" value="" id="new">
<br>
<input type="button" value=" 1 " onclick="one()" />
<input type="button" value=" 2 " onclick="two()" />
<input type="button" value=" 3 " onclick="three()" />
<input type="button" value=" + " onclick="plus()" />
</form>
</div>
代碼鏈接: - https://jsfiddle.net/archan/o9p3g1px/ – Arch
添加在評論部分中提到的jsfiddle代碼,從帖子的作者 –