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

这段js代码在firefox里可以正常运行,在ie里却报缺少对象,还请大虾们指点迷津啊。
源程序:
------------------------------------------
<html>
<head>
<title>Elements</title>
<script>
function valid(){
var total = 0;
var friends = document.form1.elements;
for (var i=0; i<friends.length; i++)
{
if (friends[i].name == "friends" && friends[i].checked)
{
total++;
}
}

if (total == 0){
document.form1.delete.disabled = true;
document.form1.update.disabled = true;
}
else if (total == 1){
document.form1.delete.disabled = false;
document.form1.update.disabled = false;
}
if (total >= 2){
document.form1.delete.disabled = true;
document.form1.update.disabled = false;
}
}
function selectAll(){
var friends = document.form1.elements;
if (document.form1.all.checked == true)
{
for (var i=0; i<friends.length; i++)
{
if (friends[i].name == "friends")
{
friends[i].checked = true;
}
}
}
else
{
for (var i=0; i<friends.length; i++)
{
if (friends[i].name == "friends")
{
friends[i].checked = false;
}
}
}
}
function selectReversed(){
var friends = document.form1.elements;
for (var i=0; i<friends.length; i++)
{
if (friends[i].name == "friends")
{
friends[i].checked = !friends[i].checked;
}
}
}
</script>
</head>

<body onload="valid();">
<form name="form1" method="get" action="">
<input type="button" name="delete" value="全选">
<input type="checkbox" name="all" onclick="selectAll();valid();" />|
<input type="button" name="update" value="反选">
<input type="checkbox" name="reversed" onclick="selectReversed();valid();" />|
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
</form>
</body>
</html>
------------------------------------------
还请高手们高知如何修改才能在ie里正常运行啊。在ie里不能正常运行,让我觉得很纳闷啊。

------解决方案--------------------
<html> 
<head> 
<title>Elements </title> 
<script type='text/javascript'> 
function valid(){ 
var total = 0; 
var friends = document.form1.elements;&