How to use document.getElementByName and getElementByTag?

前端 未结 6 1760
一生所求
一生所求 2020-11-29 08:38
 document.getElementById(\'frmMain\').elements

can i use like this

document.getElementByName(\'frmMain\').elements 
6条回答
  •  醉酒成梦
    2020-11-29 08:58

    getElementById returns either a reference to an element with an id matching the argument, or null if no such element exists in the document.

    getElementsByName() (note the plural Elements) returns a (possibly empty) HTMLCollection of the elements with a name matching the argument. Note that IE treats the name and id attributes and properties as the same thing, so getElementsByName will return elements with matching id also.

    getElementsByTagName is similar but returns a NodeList. It's all there in the relevant specifications.

提交回复
热议问题