老师 帮我看下 还右什么需要更改或者优化的吗?
<!DOCTYPE html>
<html>
<head>
<title> 事件</title>
</head>
<body>
<input type='text' id='num1' />
<select id='operate'>
<option value='+' name="v1">+</option>
<option value="-" name="v2">-</option>
<option value="*" name="v3">*</option>
<option value="/" name="v4">/</option>
</select>
<input type='text' id='num2' />
<input type='button' value=' = ' onclick="count()" />
<input type='text' id='result' />
<script type="text/javascript">
var num1 = document.getElementById("num1"),
num2 = document.getElementById("num2"),
operate = document.getElementById("operate"),
result = document.getElementById("result");
var m = {
add:function(num1,num2){
return +num1.value + +num2.value;
},
did:function(num1,num2){
return num1.value - num2.value;
},
mul:function(num1,num2){
return num1.value * num2.value;
},
ddd:function(num1,num2){
return num1.value / num2.value;
},
}
function count() {
/*此处写代码*/
switch(operate.value){
case "+":
result.value = m.add(num1,num2);
break;
case "-":
result.value = m.did(num1,num2);
break;
case "*":
result.value = m.mul(num1,num2);
break;
case "/":
result.value = m.ddd(num1,num2);
break;
}
}
</script>
</body>
</html>
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星