<input type="text" id="num1" value="" />
<select id="mySelect">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" id="num2" value="" />
<input type="button" id="jisuan" value="计算" />
//js
<script>
var oTxt1 = document.getElementById('num1')
var oTxt2 = document.getElementById('num2')
var oSelect = document.getElementById('mySelect')
var oBtn = document.getElementById('jisuan')
oBtn.onclick=function(){
switch(oSelect.value){
case '+':
alert(parseInt(oTxt1.value)+parseInt(oTxt2.value))
break
case '-':
alert(parseInt(oTxt1.value)-parseInt(oTxt2.value))
break
case '*':
alert(parseInt(oTxt1.value)*parseInt(oTxt2.value))
break
case '/':
if(parseInt(oTxt2.value) !== 0){
alert(parseInt(oTxt1.value)/parseInt(oTxt2.value))
}else{
alert('除数不能为0')
}
break
default:
alert('Bug!!!')
}
}
</script>
解:加法:加数A+加数B=和C验算:用和减去一个加数,必须等于另一个加数,否则计算错误。C-A=BC-B=A减法:被减数A-减数B=差C验算:用被减数减差,必须等于减数,即A-C=B用减数加上差,和必须等于被减数,即B+C=A