中易网

用html语言写一个计算器

答案:1  悬赏:0  
解决时间 2021-11-13 08:22
这是我的代码,刚开始学,请问接下来要怎么做啊
<!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>
最佳答案
<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>
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
海尔冰箱搬运注意事项有哪些?
藏式建筑装饰的特点是什么?
秦智虞愚的意思?成语怎么解释?
为什么比基尼脱毛
寻求杭州西湖附近的美食攻略
电梯工程施工工艺标准是什么?
泥猪瓦狗打一数字
林场村怎么去啊,我要去那办事
在北京大兴电动车到那办牌,多少钱
长沙哪里有胡椒猪肚鸡吃啊!
打了狂犬疫苗针后记性不好有什么东西可以补回
做梦梦见老公被别人打死了是什么意思?好不好
毕业论文的研究方法及技术路线怎么写
薄荷有副作用吗
老板办公室适合摆放什么植物
推荐资讯
网购法律有何规定
沈阳晋级装饰工程有限公司的设计水平高吗?
法语:关于半助动词的否定的问题,例:Elleve
深圳园比力恒科技有限公司工商注册信息资料市
2016年小升初政策是什么?
会有人喜欢宅男吗?
农行西安文景路支行地址有知道的么?有点事想
传染性软疣去哪儿治得好?
游览的文章(范文)
风餐水栖的意思?成语怎么解释?
急!请问腰不好的老人要吃什么补品?
如何使换气扇风力大?
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?