日期:2014-05-16  浏览次数:20334 次

为什么这段代码在火狐中正确的没有问题,在IE下却不行?
<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=UTF-8 "   />
<title> Untitled   Document </title>
</head>
<body>
<form   action= "somepage.php "   method= "post "   name= "theForm ">
<dl>
<dd> <input   type= "checkbox "   name= "option1 "> 1 </dd>
<dd> <input   type= "checkbox "   name= "option2 "> 2 </dd>
<dd> <input   type= "checkbox "   name= "option3 "> 3 </dd>
<dd> <input   type= "checkbox "   name= "option4 "> 4 </dd>
<dd> <input   type= "checkbox "   name= "option5 "> 5 </dd>
<dd> <input   type= "checkbox "   name= "option6 "> 6 </dd>
<dd> <input   type= "checkbox "   name= "option7 "> 7 </dd>
</dl>
<input   name= "submit "   type= "submit "   value= "Submit   ! ">
</form>
</body>
</html>
<script   language= "JavaScript "   type= "text/javascript ">
document.forms[0].elements[ "submit "].onclick=function(){
var   checkedCount=0;
for   (var   i=0;i <document.forms[0].elements.length;i++){
if(document.forms[0].elements[i].checked)checkedCount++;
}
if(checkedCount> 5   ||   checkedCount <3){
alert( "请选择3-5个选项! ");
return   false;
}
return   true;
}
</script>


为什么这段代码在火狐中正确的没有问题,在IE下却不行?

------解决方案--------------------
我测试没有问题啊。
修改成这样呢?
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=UTF-8 " />
<title> Untitled Document </title>
<script language= "JavaScript " type= "text/javascript ">
window.onload = function () {
document.forms[0].elements[ "submit "].onclick = function () {
var checkedCount = 0;
var Item = this.form.elements;
for (var i = 0; i < Item.length; i ++) {
if (Item[i].checked)
checkedCount ++;
}
if (checkedCount > 5 || checkedCount < 3) {
alert( "请选择3-5个选项! ");
return false;
}
return true;
}
}
</script>
</head>
<body>
<form action= "somepage.php " method= "post " name= "theForm ">
<dl>
<dd> <input type= "checkbox " name= "option1 "> 1 </dd>
<dd> <input type= "checkbox " name= "option2 "> 2 </dd>
<dd> <input type= "checkbox " name= "option3 "> 3 </dd>
<dd> <input type= "checkbox " name= "option4 "> 4 </dd>
<dd> <input type= "checkbox " name= "option5 "> 5 </dd>
<dd> <input type= "checkbox " name= "option6 "> 6 </dd>
<dd> <input type= &qu