2017-03-08 15 views
0

首先,你好,我是這個網站的新手,我也很新,還在學習。我一直在做一個計算器,作爲一個小型的初學者項目。我在減法部分有一些問題。我會發布我的全部工作,也許會出現一些想法。謝謝! //我用的支架,如果有人只是想知道第一個計算器的減法代碼

<html> 
<head> 
</head> 
<body> 
<form name="frm"> 

<input name="result"> 
</br> 
<input type="button" name="1" value="1" onClick="run1()"> 
<input type="button" name="1" value="2" onClick="run2()"> 
<input type="button" name="1" value="3" onClick="run3()"> 
<input type="button" name="1" value="4" onClick="run4()"> 
<input type="button" name="1" value="5" onClick="run5()"> 
<input type="button" name="1" value="6" onClick="run6()"> 
<input type="button" name="1" value="7" onClick="run7()"> 
<input type="button" name="1" value="8" onClick="run8()"> 
<input type="button" name="1" value="9" onClick="run9()"> 
<input type="button" name="plus" value="+" onClick="runplus()"> 
</br> 
<input type="button" name="calc" value="=" onClick="evalu()"> 
</form> 
<script type="text/JavaScript"> 

function run1() 
{document.frm.result.value += "1";} 
function run2() 
{document.frm.result.value += "2";} 
function run3() 
{document.frm.result.value += "3";} 
function run4() 
{document.frm.result.value += "4";} 
function run5() 
{document.frm.result.value += "5";} 
function run6() 
{document.frm.result.value += "6";} 
function run7() 
{document.frm.result.value += "7";} 
function run8() 
{document.frm.result.value += "8";} 
function run9() 
{document.frm.result.value += "9";} 
function runplus() 
{document.frm.result.value += "+";} 

function evalu(){ 

var evalo = eval(document.frm.result.value) 

document.frm.result.value = evalo; 

} 


</script> 
</body> 
</html> 

回答

0

這實際上不是建立一個計算器最優或有效的方法;然而,既然你是全新的,我們現在就可以把它推到一邊。歡迎使用JavaScript! :D

您應該能夠創建一個減號按鈕,就像您創建了加號按鈕一樣。

<input type="button" value="-" onClick="runminus()">

的Javascript:

function runminus() { 
    document.frm.result.value += "-"; 
}