马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>数字计算器</title>
<script>
var objDisdiv = document.getElementById("disdiv");
var objNum1div = document.getElementById("num1");
var objNum2div = document.getElementById("num2");
function addcirculater(){
var num1 = Number(objNum1div.value);
var num2 = Number(objNum2div.value) ;
var addNum = num1+num2;
objDisdiv.innerHTML = addNum;
}
function subcirculater(){
var num1 = objNum1div.value;
var num2 = objNum2div.value;
var subNum = num1 - num2;
objDisdiv.innerHTML = subNum;
}
function mutcirculater(){
var num1 = objNum1div.value;
var num2 = objNum2div.value;
var mutNum = num1 * num2;
objDisdiv.innerHTML = mutNum;
}
function divcirculater(){
var num1 = objNum1div.value;
var num2 = objNum2div.value;
var divNum = num1 / num2;
objDisdiv.innerHTML = divNum;
}
</script>
<style>
#disdiv{
height: 50px;
}
</style>
</head>
<body>
<div id="div">
请输入第一个数字:<input type="text" id ="num1" /><br />
请输入第二个数字:<input type="text" id ="num2" /><br />
<button type="button" id="addbu" onclick="addcirculater()">+</button>
<button type="button" id="subbu" onclick="subcirculater()">-</button>
<button type="button" id="mutbu" onclick="mutcirculater()">*</button>
<button type="button" id="divbu" onclick="divcirculater()">/</button>
</div>
<h3>计算结果:</h3>
<div id = "disdiv">
</div>
</body>
</html>
|