<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>简单计算器</title>
</head>
<body>
<input type="text">
<select id="select">
<option value="add">+</option>
<option value="dis">-</option>
<option value="che">*</option>
<option value="chu">/</option>
</select>
<input type="text">
<input type="button" value="=">
<input type="text">
</body>
<script>
var inps = document.getElementsByTagName("input");
var select = document.getElementById("select");
inps[2].onclick = function(){
var a = Number(inps[0].value);
var b = Number(inps[1].value);
var value =select.value;
switch(value){
case "add":
inps[3].value=(a+b);
break;
case "dis":
inps[3].value=(a-b);
break;
case "che":
inps[3].value=(a*b);
break;
case "chu":
inps[3].value=(a/b);
break;
}
}
</script>
</html>
JS写一个简易计算器
猜你喜欢
转载自blog.csdn.net/lanseguhui/article/details/80848413
今日推荐
周排行