0

以下は私のコードです。. .

<div id="calc">

<input id="screen"></div>
<div id="subkeys">
<div  class="btn1">log</div>
<div  class="btn1">ln</div>
<div  class="btn1">(-)</div>
<div  class="btn1">sin</div>
<div  class="btn1">cos</div>
<div  class="btn1">tan</div>
<div  class="btn1">sin<sup>-1</sup></div>
<div  class="btn1">cos<sup>-1</sup></div>
<div  class="btn1">tan<sup>-1</sup></div>
</div>
<div id="mainkeys">
<div name="del" value="" onClick="rundel()" class="btn2 btn-del">DEL</div>
<div name="minus" value="-" onClick="runminus()" class="btn2 btn-minus">-</div>
<div name="multi" value="x" onClick="runmulti()" class="btn2 btn-multi">x</div>
<div name="plus" value="+" onClick="runplus()" class="btn2 btn-plus">+</div>
<div name="1" value="1" onClick="addDigit(1)" class="btn2 num">1</div>
<div name="2" value="2" onClick="addDigit(2)" class="btn2 num">2</div>
<div name="3" value="3" onClick="addDigit(3)" class="btn2 num">3</div>
<div name="div" value="÷" onClick="rundiv()" class="btn2 btn-div">÷</div>
<div name="ans" value="ans" onClick="runans()" class="btn2 btn-ans">ANS</div>
<div name="0" value="0" onClick="addDigit(0)" class="btn2 num">0</div>
<div name="eq" value="=" onClick="runeq()" class="btn2 btn-eq">=</div>
</div>

<script>
function addDigit(digit) {  
document.getElementById('output').value += digit;     
}
function rundel(){document.getElementById('output').value = "";}
function runminus(){document.getElementById('output').value = "";}
function runplus(){document.getElementById('output').value = "";}
function rundiv(){document.getElementById('output').value = "";}
function runmulti(){document.getElementById('output').value = "";}
function runeq(){
var result = eval(document.getElementById('output').value = "")
    document.getElementById('output').value = result;
}
</script>

2 つの数値を加算、減算、除算、または乗算しようとすると、得られる結果は UNDEFINED です。結果が必要です。. .

リンクはこちら

4

2 に答える 2

0
<script>
function addDigit(digit) {  
document.getElementById('output').value += digit;     
}
function rundel(){document.getElementById('output').value = "";}
function runminus(){document.getElementById('output').value = "";}
function runplus(){document.getElementById('output').value = "";}
function rundiv(){document.getElementById('output').value = "";}
function runmulti(){document.getElementById('output').value = "";}
function runeq(){
var result = eval(document.getElementById('output').value);
    document.getElementById('output').value = result;
</script>

これを試して...

于 2013-10-21T10:35:02.333 に答える