<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<input type="text" name="input1" id="input1" value="" />
<input type="text" name="input2" id="input2" value="" />
<br />
<input type="button" name="btn1" id="btn1" value="求和" />
<input type="button" name="btn2" id="btn2" value="求差" />
<input type="button" name="btn3" id="btn3" value="求积" />
<input type="button" name="btn4" id="btn4" value="求商" />
<input type="button" name="btn5" id="btn5" value="求余" />
<script type="text/javascript">
// 元素获取
var oTxt1 = document.getElementById("input1");
var oTxt2 = document.getElementById("input2");
var oBtn1 = document.getElementById("btn1");
var oBtn2 = document.getElementById("btn2");
var oBtn3 = document.getElementById("btn3");
var oBtn4 = document.getElementById("btn4");
var oBtn5 = document.getElementById("btn5");
// 绑定事件
// 求和
oBtn1.onclick = function (){
alert(parseFloat(oTxt1.value) + parseFloat(oTxt2.value));
}
// 求差
oBtn2.onclick = function (){
alert(parseFloat(oTxt1.value) - parseFloat(oTxt2.value));
}
// 求积
oBtn3.onclick = function (){
alert(parseFloat(oTxt1.value) * parseFloat(oTxt2.value));
}
// 求商
oBtn4.onclick = function (){
alert(parseFloat(oTxt1.value) / parseFloat(oTxt2.value));
}
// 求余
oBtn5.onclick = function (){
alert(parseInt(oTxt1.value) % parseInt(oTxt2.value));
}
</script>
</body>
</html>