<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>http://www.gxaedu.com</title>
</head>
<body>
<input type="number" id="text1">
<select>
<option>+</option>
<option>-</option>
<option>*</option>
<option>/</option>
<option>%</option>
</select>
<input type="number" id="text2">
<input type="button" value="计算" id="btn1">
</body>
<script>
var oText1=document.getElementById('text1');
var oText2=document.getElementById('text2');
var oSlt=document.getElementsByTagName('select')[0];
var oBtn=document.getElementById('btn1');
oBtn.function () {
switch (oSlt.value) {
case '+':
alert(parseInt(oText1.value) + parseInt(oText2.value));
break;
case '-':
alert(parseInt(oText1.value) - parseInt(oText2.value));
break;
case '*':
alert(parseInt(oText1.value) * parseInt(oText2.value));
break;
case '/':
alert(parseInt(oText1.value) / parseInt(oText2.value));
break;
case '%':
alert(parseInt(oText1.value) % parseInt(oText2.value));
break;
}
}
</script>
</html>
JS_简易计算器
最新推荐文章于 2023-11-14 10:53:55 发布