用html语言写一个计算器
这是我的代码,刚开始学,请问接下来要怎么做啊<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http:/...
这是我的代码,刚开始学,请问接下来要怎么做啊
<!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> 展开
<!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> 展开
1个回答
展开全部
<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>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询