document.getElementById(“selAge”) Vs document.myForms.selAge

后端 未结 4 2006
予麋鹿
予麋鹿 2020-12-22 04:05

What is difference between

document.getElementById(“selAge”) 
document.myForms.selAge

When to use which?

4条回答
  •  天涯浪人
    2020-12-22 04:51

    The second one is an absolute no-no! It first finds an element with id/name "myForms" and gets its child, with id/name "selAge". The first one finds any element with the id "selAge". Always use the first one ... because, someone, in the future may decide to put "myForms" into a div. Then you're in a fix.

提交回复
热议问题