这是效果图和代码,两个题都是求 + 、,- 、 x 、 / 只是方法不同而已,希望大家解答难题。
3 回答
已采纳
阿旭_
TA贡献217条经验 获得超353个赞
第一个数:<input type="text" id="txt1"/><br/>
第二个数:<input type="text" id="txt2"/><br/>
计算结果:<input type="text" id="txt3"/><br/>
<input type="button" value="+" onclick="setOp('+');"/>
<input type="button" value="-" onclick="setOp('-');"/>
<input type="button" value="*" onclick="setOp('*');"/>
<input type="button" value="/" onclick="setOp('/');"/>
<script>
function setOp(t){
var t1 = document.getElementById("txt1");
var t2 = document.getElementById("txt2");
document.getElementById("txt3").value = eval(t1.value+t+t2.value);
}
</script>
添加回答
举报
0/150
提交
取消
