下面是一段简单的计算器代码,我想通过id="result"的DIV显示计算结果,就是不知道该如何写出计算结果。有没有高手讲解一下。
<span>计算器</span><br />
<!-- 输入框 start--><input type="text" id="math" /><!-- 输入框 end-->
<!-- 计算结果显示 start--><div id="result"></div><!-- 计算结果显示 end-->
<br />
<!-- 按钮 start-->
<input type="button" id="count1" value="+" onclick="result_count(0)" />
<input type="button" id="count2" value="-" onclick="result_count(1)" />
<input type="button" id="count3" value="×" onclick="result_count(2)" />
<input type="button" id="count4" value="÷" onclick="result_count(3)" />
<!-- 等于号 start--><input type="button" id="equal" value="=" onclick="equal()" /><br /><!-- 等于号 end-->
<input type="button" id="one" value="1" onclick="math_n(1)" />
<input type="button" id="two" value="2" onclick="math_n(2)" />
<input type="button" id="three" value="3" onclick="math_n(3)" />
<input type="button" id="four" value="4" onclick="math_n(4)" />
<input type="button" id="nine" value="5" onclick="math_n(5)" />
<input type="button" id="six" value="6" onclick="math_n(6)" />
<input type="button" id="seven" value="7" onclick="math_n(7)" />
<input type="button" id="eight" value="8" onclick="math_n(8)" />
<input type="button" id="nine" value="9" onclick="math_n(9)" />
<input type="button" id="zero" value="0" onclick="math_n(0)" />
<input type="button" id="count5" value="." onclick="result_count(4)" />
<script type="text/javascript">
for(m=0;m<=9;m++){
function math_n(m){
document.getElementById("math").value+=m
}
}
var arr = new Array(5)
arr[0] = "+"
arr[1] = "-"
arr[2] = "*"
arr[3] = "/"
arr[4] = "."
for(c=0;c<=4;c++){
function result_count(c){
document.getElementById("math").value+=arr[c]
}
}
</script>
<!-- 按钮 end-->
<span>计算器</span><br />
<!-- 输入框 start--><input type="text" id="math" /><!-- 输入框 end-->
<!-- 计算结果显示 start--><div id="result"></div><!-- 计算结果显示 end-->
<br />
<!-- 按钮 start-->
<input type="button" id="count1" value="+" onclick="result_count(0)" />
<input type="button" id="count2" value="-" onclick="result_count(1)" />
<input type="button" id="count3" value="×" onclick="result_count(2)" />
<input type="button" id="count4" value="÷" onclick="result_count(3)" />
<!-- 等于号 start--><input type="button" id="equal" value="=" onclick="equal()" /><br /><!-- 等于号 end-->
<input type="button" id="one" value="1" onclick="math_n(1)" />
<input type="button" id="two" value="2" onclick="math_n(2)" />
<input type="button" id="three" value="3" onclick="math_n(3)" />
<input type="button" id="four" value="4" onclick="math_n(4)" />
<input type="button" id="nine" value="5" onclick="math_n(5)" />
<input type="button" id="six" value="6" onclick="math_n(6)" />
<input type="button" id="seven" value="7" onclick="math_n(7)" />
<input type="button" id="eight" value="8" onclick="math_n(8)" />
<input type="button" id="nine" value="9" onclick="math_n(9)" />
<input type="button" id="zero" value="0" onclick="math_n(0)" />
<input type="button" id="count5" value="." onclick="result_count(4)" />
<script type="text/javascript">
for(m=0;m<=9;m++){
function math_n(m){
document.getElementById("math").value+=m
}
}
var arr = new Array(5)
arr[0] = "+"
arr[1] = "-"
arr[2] = "*"
arr[3] = "/"
arr[4] = "."
for(c=0;c<=4;c++){
function result_count(c){
document.getElementById("math").value+=arr[c]
}
}
</script>
<!-- 按钮 end-->
解决方案 »
- 关于 js 的位置问题。
- 为什么如果超类对象中有事件,则子类中必须用for(var i in PersonC.prototype)来实现继承,而用StudentC.prototype =
- 如何去掉IE标题栏及边框
- 怎么样让选中其中一个input的时候也同时选中其它的input
- js截图
- 谁帮我写个加密和解密的函数?
- 各位帮助我看一下,这是什么问题,为什么,我的信箱登不过去。
- look look study study
- 怎么样使点了按钮后,当前页被刷新?是不是在onclick里写?怎么写?
- 这句话中为什么打出111111111呢
- css3 pie插件不支持 box-shadow inset
- EXT高手进
<span>计算器</span><br />
<!-- 输入框 start--><input type="text" id="math" /><!-- 输入框 end-->
<!-- 计算结果显示 start--><div id="result"></div><!-- 计算结果显示 end-->
<br />
<!-- 按钮 start-->
<input type="button" id="count1" value="+" onclick="result_count(0)" />
<input type="button" id="count2" value="-" onclick="result_count(1)" />
<input type="button" id="count3" value="×" onclick="result_count(2)" />
<input type="button" id="count4" value="÷" onclick="result_count(3)" />
<!-- 等于号 start--><input type="button" id="equal" value="=" onclick="equal()" /><br /><!-- 等于号 end-->
<input type="button" id="one" value="1" onclick="math_n(1)" />
<input type="button" id="two" value="2" onclick="math_n(2)" />
<input type="button" id="three" value="3" onclick="math_n(3)" />
<input type="button" id="four" value="4" onclick="math_n(4)" />
<input type="button" id="nine" value="5" onclick="math_n(5)" />
<input type="button" id="six" value="6" onclick="math_n(6)" />
<input type="button" id="seven" value="7" onclick="math_n(7)" />
<input type="button" id="eight" value="8" onclick="math_n(8)" />
<input type="button" id="nine" value="9" onclick="math_n(9)" />
<input type="button" id="zero" value="0" onclick="math_n(0)" />
<input type="button" id="count5" value="." onclick="result_count(4)" />
<input type="button" id="reset" value="C" onclick="reset()" />
<script type="text/javascript">
for(m=0;m<=9;m++){
function math_n(m){
document.getElementById("math").value+=m
}
}
var arr = new Array(5)
arr[0] = "+"
arr[1] = "-"
arr[2] = "*"
arr[3] = "/"
arr[4] = "."
for(c=0;c<=4;c++){
function result_count(c){
document.getElementById("math").value+=arr[c]
}
}
function equal()
{
document.getElementById('result').innerHTML = eval('('+document.getElementById("math").value+')');
}
function reset()
{
document.getElementById('result').innerHTML="";
document.getElementById("math").value="";
}
</script>
<!-- 按钮 end-->