简易计算器实现
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input type="text" value="" id="txt1">
<select id="selectin">
<option>+</option>
<option>-</option>
<option>*</option>
<option>/</option>
</select>
<input type="text" value="" id="txt2">
<button id="btn">计算</button>
<input type="text" readonly id="result">
</body>
<script>
btn.onclick = function(){
if(selectin.value == '+'){
result.value = Number(txt1.value) + Number(txt2.value);
}
if(selectin.value == '-'){
result.value = txt1.value - txt2.value;
}
if(selectin.value == '*'){
result.value = txt1.value * txt2.value;
}
if(selectin.value == '/'){
result.value = txt1.value / txt2.value;
}
}
</script>
</html>