这是我的代码,刚开始学,请问接下来要怎么做啊
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> 计算器</title>
<script>
var tmp=0;
function add(x,y){
return Number(x) + Number(y);
}
function getresult(){
var x = document.getElementById("button0").value;
var y = document.getElementById("button0").value;
var re = add(x,y);
document.getElementById("txt1").value = re;
}
function getNumber(obj){
var str = document.getElementById("txt1").value;
document.getElementById("txt1").value = str + obj.value;
}
</script>
</head>
<body>
<table border="1" align="center">
<caption>
<input type="text" id="txt1" style="text-align:right"/>
<input type="text" id="txt2" style="display:none"/>
<table class=1>
<tr>
<td><input type="button" onclick="getNumber(this)" id="button7" value="7"></td>
<td><input type="button" onclick="getNumber(this)" id="button8" value="8"></td>
<td><input type="button" onclick="getNumber(this)" id="button9" value="9"></td>
<td><input type="button" onclick="getNumber(this)" id="button*" value="*"></td>
</tr>
<tr>
<td><input type="button" onclick="getNumber(this)" id="button4" value="4"></td>
<td><input type="button" onclick="getNumber(this)" id="button5" value="5"></td>
<td><input type="button" onclick="getNumber(this)" id="button6" value="6"></td>
<td><input type="button" onclick="getNumber(this)" id="button-" value="-"></td>
</tr>
<tr>
<td><input type="button" onclick="getNumber(this)" id="button1" value="1"></td>
<td><input type="button" onclick="getNumber(this)" id="button2" value="2"></td>
<td><input type="button" onclick="getNumber(this)" id="button3" value="3"></td>
<td><input type="button" onclick="getNumber(this)" id="Button13" value="+" /></td>
</tr>
<tr>
<td><input type="button" onclick="getNumber(this)" id="button0" value="0"></td>
<td><input type="button" onclick="getNumber(this)" id="button." value="."></td>
<td><input type="button" onclick="getresult()" id="button=" value="="></td>
<td><input type="button" onclick="getNumber(this)" id="button/" value="/"></td>
</tr>
</table>
</body>
</html>
用html语言写一个计算器
答案:1 悬赏:0
解决时间 2021-11-13 08:22
- 提问者网友:猖狂醉薇
- 2021-11-12 21:53
最佳答案
- 二级知识专家网友:懂得ㄋ、沉默
- 2021-11-12 23:27
<script>
var tmp=0;
function add(x){
var sum =eval(x);
return sum;
}
function getresult(){
var x = document.getElementById("txt1").value;
var re = add(x);
document.getElementById("txt1").value = re;
}
function getNumber(obj){
var str = document.getElementById("txt1").value;
document.getElementById("txt1").value = str + obj.value;
}
</script>
var tmp=0;
function add(x){
var sum =eval(x);
return sum;
}
function getresult(){
var x = document.getElementById("txt1").value;
var re = add(x);
document.getElementById("txt1").value = re;
}
function getNumber(obj){
var str = document.getElementById("txt1").value;
document.getElementById("txt1").value = str + obj.value;
}
</script>
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯