document.getElementById("myCheck")不是一个集合,用document.all.myCheck.length

解决方案 »

  1.   

    var blnSelected = true
    function selectAll()
    {
    var selectedItems
    selectedItems = document.all.myCheck
    if(selectedItems == null ) return false
    if(selectedItems.length == null) selectedItems.checked = blnSelected
    for(var i=0;i<selectedItems.length;i++) selectedItems[i].checked = blnSelected
    blnSelected = !blnSelected
    }
      

  2.   

    各位,用all只能在IE上用,而getElementById能在IE和Netscape上使用。用all我早就弄出来了。
      

  3.   

    document.getElementById只能得到一个元素,不能是集合,要得到集合,用
    d=document.getElementsByTagName("INPUT")
    for(i=0;i<d.length;i++)
    {
    if(d[i].id=="myCheck")
    {
    //做你要处理的事情
    }
    }也可以这样:
    d=document.getElementsByName("myCheckName") //这里用input type=checkbox的name属性
    for(i=0;i<d.length;i++)
    {
    //做你要处理的事情
    }
      

  4.   

    getElementById Method
    --------------------------------------------------------------------------------Returns a reference to the first object with the specified value of the ID attribute.SyntaxoElement = document.getElementById(sIDValue)ParameterssIDValue Required. String that specifies the value of an ID attribute. Return ValueReturns the first object with the same ID attribute as the specified value.ResIf the ID value belongs to a collection, the getElementById method returns the first object in the collection.-------------------------------------------------------------------From above, We can see that the method(document.getElementById) can only get ONE DOM element.Try Other Methods.
      

  5.   

    document.getElementsByTagName()
    document.getElementsByName()These tow method can return the collection you want.
      

  6.   

    document.getElementsByTagName()
    document.getElementsByName()
    document.getElementById()Notice the letter "s" follows Element.
      

  7.   

    自己写一个getElementsById
    <input id="id1" value=1>
    <input id="id0" value=2>
    <input id="id1" value=3>
    <input name="id1" value=4><script>
    function document.getElementsById(sid){
      var obja=new Array();
      var objs=document.getElementsByName(sid);
      for(i=0;i<objs.length;i++)
         if(objs[i].id==sid)
              {obja.length++;obja[obja.length-1]=objs[i];}
      return obja;
    }
    id1s=document.getElementsById("id1");
    for(i=0;i<id1s.length;i++)
     alert(id1s[i].value)
    </script>