同样的代码,换成getElementsByClassName和class就计算不来,这是为什么
<!DOCTYPE html>
<html>
<head>
<title> 事件</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function count(){
var num1=document.getElementById("num1").value;
var num2=document.getElementById("num2").value;
var fuhao=document.getElementById("fuhao").value;
var num3;
switch(fuhao){
case "+":num3=parseInt(num1)+parseInt(num2); break;
case "-":num3=parseInt(num1)-parseInt(num2); break;
case "*":num3=parseInt(num1)*parseInt(num2); break;
default :num3=parseInt(num1)/parseInt(num2);
}
document.getElementById("num3").value=num3;
}
</script>
</head>
<body>
<form>
<input type="text" id="num1"/>
<select id="fuhao">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" id="num2"/>
<input type="button" value="=" onClick="count()"/>
<input type="text" id="num3"/>
</form>
</body>
</html>