<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>事件练习</title>
<script type="text/javascript">
function count(){
var text1=parseInt(document.getElementById("text1").value);
var select=parseInt(document.getElementById("select").value);
var text2=parseInt(document.getElementById("text2").value);
var result='';
switch(select)
{
case '+':
result=text1+text2;break;
case "-":
result=text1-text2;break;
case "*":
result=text1*text2;break;
case "/":
result=text1/text2;break;
}
document.getElementById("text3").value=result;
}
</script>
</head>
<body>
<form action="">
<input type="text" id="text1"/>
<select id="select">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" id="text2"/>
<input type="button" value="=" onclick = "count()" />
<input type="text" id="text3"/>
</form>
</body>
</html>
var select = document.getElementById("select").value
把那句话改成这样就行了
var select=parseInt(document.getElementById("select").value)
操作符为什么要用parseInt转一下呢。
看半天没看懂你要问什么