<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<script>
function CheckAll(form){
  if(document.all.chkall.checked){
   document.all.chkall.checked=false;
  }else{
   document.all.chkall.checked=true;
  }
  for (var i=0;i<form.elements.length;i++){
    var e = myForm.elements[i];
    if (e.name != 'chkall')
       e.checked = myForm.chkall.checked;
    }
}
</script>
<BODY><form name="myForm">
<input type="checkbox">1
<input type="checkbox">2
<input type="checkbox">2
<hr>
<input type="hidden" id="Action" name="Action" value="">
<input type="button" id="chkall1" name="chkall1" value=" 全 选 " onClick="CheckAll(this.form);">
<input type="checkbox" name="chkall" value="checkbox" style="display:none;">
</form></BODY>
</HTML>
上面的js,在没有第一行声明时,FF/ie都没问题,但一加入第一行声明,就都不行了请大家帮我改改js部分 谢谢

解决方案 »

  1.   

    上面的代码在IE6正常
    和你html文件格式有关系 ?
      

  2.   

    不知道你哪来的 chkall 这个元素
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
    <script>
    var checked;
    function CheckAll(form){
      if(checked){
         checked = false; 
      }else{
         checked = true; 
      }  for (var i=0;i<form.elements.length-1;i++){
        var e = document.myForm.elements[i];
        if (e.name != 'chkall')
           e.checked = checked;
        }
    }
    </script>
    <BODY><form name="myForm">
    <input type="checkbox">1
    <input type="checkbox">2
    <input type="checkbox">3
    <hr>
    <input type="hidden" id="Action" name="Action" value="">
    <input type="button" id="chkall1" name="chkall1" value=" 全 选 " onClick="CheckAll(this.form);">
    <input type="checkbox" name="chkall" value="checkbox" style="display:none;">
    </form></BODY>
    </HTML>
      

  3.   

    错误1: 不要用document.all
    错误2: Form名称前要加document. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
    <script>
    function CheckAll(form){
      if(document.myForm.chkall.checked){
          document.myForm.chkall.checked=false;
      }else{
          document.myForm.chkall.checked=true;
      }  for (var i=0;i<form.elements.length-1;i++){
        var e = document.myForm.elements[i];
        if (e.name != 'chkall')
           e.checked = document.myForm.chkall.checked;
        }
    }
    </script>
    <BODY><form name="myForm">
    <input type="checkbox">1
    <input type="checkbox">2
    <input type="checkbox">2
    <hr>
    <input type="hidden" id="Action" name="Action" value="">
    <input type="button" id="chkall1" name="chkall1" value=" 全 选 " onClick="CheckAll(this.form);">
    <input type="checkbox" name="chkall" value="checkbox" style="display:snone;">
    </form></BODY>
    </HTML>
      

  4.   

    谢谢 griefforyou ^_^谢谢大家:)