var ElementLen = document.getElementsByName("xid")
通吃2种情况

解决方案 »

  1.   

    1个的时候不是数组,所以没有length属性
    写成
    document.getElementsByName("xid").length
      

  2.   

    var ElementLen = document.getElementsByName("xid")
    这种写法不管一个还是多个,都正常
      

  3.   

    多谢2位老兄,,明白了。。只怪偶学习时没认真,没用心。--------------
    getElementById Returns a reference to the first object with the specified value of the ID attribute. 
    getElementsByName Retrieves a collection of objects based on the value of the NAME attribute. 
    getElementsByTagName Retrieves a collection of objects based on the specified element name.