展开全部
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> New Document </title>
<script language="javascript">
var one = document.getElementById("t1").value;
var two = document.getElementById("t2").value;
function times(){
var one = document.getElementById("t1").value;
var two = document.getElementById("t2").value;
document.getElementById("text1").value =Number(one) * Number(two);
}
function divide(){
var one = document.getElementById("t1").value;
var two = document.getElementById("t2").value;
if(two == "0"){
alert("被除数不能为0");
document.getElementById("t2").value = "";
}
document.getElementById("text1").value =Number(one) / Number(two);
}
function plus(){
var one = document.getElementById("t1").value;
var two = document.getElementById("t2").value;
document.getElementById("text1").value =Number(one) + Number(two);
}
function minus(){
var one = document.getElementById("t1").value;
var two = document.getElementById("t2").value;
document.getElementById("text1").value =Number(one) - Number(two);
}
</script>
</head>
<body>
请输入第一个数:<input id="t1" type="text"/><br/>
请输入第二个数:<input id="t2" type="text"/><br/>
结果:<input id="text1" type="text" class="tool" ></input><br/>
<input id="btn1" type="button" class="tool" onclick="times()" value="×"></input>
<input id="btn2" type="button" class="tool" onclick="divide()" value="÷"></input>
<input id="btn3" type="button" class="tool" onclick="plus()" value="+"></input>
<input id="btn4" type="button" class="tool" onclick="minus()" value="-"></input>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询