# 初学者JS计算器

[英]Beginner JS calculator

` `var displayText = document.getElementById('displayText'); var output = document.getElementById('output'); function add(){ var two, plus, result; result = displayText.value; output.innerHTML = result; } function addOne() { var one = document.getElementById('one').value = 1; displayText.value = one; } function addTwo() { var two = document.getElementById('two').value = 2; displayText.value = two; } function addPlus() { var plus = document.getElementById('plus').value = "+"; displayText.value = plus; }` `
` ` <div> <div class="display"> <input type="text" id="displayText" name="" value=""> <p>The result of your calculation is: <span id="output"></span></p> </div> <div class="btn_wrap"> <button id="one" onclick="addOne()">1</button> <button id="two" onclick="addTwo()">2</button> <button id="plus" onclick="addPlus()">+</button> <button id="" onclick="add()">Add</button> </div> </div>` `

``````displayText.value = one;
``````

``````displayText.value += one;
``````

``````function addOne() {
var one = document.getElementById('one').value = 1;
displayText.value = displayText.value + one;
}
var two = document.getElementById('two').value = 2;
displayText.value =displayText.value + two;
}
``````

` `var displayText = document.getElementById('displayText'); var output = document.getElementById('output'); function add() { var two, plus, result; result = displayText.value; output.innerHTML = eval(result); } function addOne() { var one = document.getElementById('one').innerText; displayText.value += one; } function addTwo() { var two = document.getElementById('two').innerText ; displayText.value += two; } function addPlus() { var plus = document.getElementById('plus').innerText ; displayText.value += plus; }` `
` `<div> <div class="display"> <input type="text" id="displayText" name="" value=""> <p>The result of your calculation is: <span id="output"></span></p> </div> <div class="btn_wrap"> <button id="one" onclick="addOne()">1</button> <button id="two" onclick="addTwo()">2</button> <button id="plus" onclick="addPlus()">+</button> <button id="" onclick="add()">Add</button> </div> </div>` `