document.getElementById(“selAge”)与document.myForms.selAge [英] document.getElementById(“selAge”) Vs document.myForms.selAge

查看:103
本文介绍了document.getElementById(“selAge”)与document.myForms.selAge的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



What is difference between

document.getElementById("selAge") 
document.myForms.selAge

何时使用哪个?

推荐答案

document.getElementById()是获取元素引用的推荐方式。如果您决定更改表单名称或ID,则使用起来更方便,也不需要进行任何更改。
然而,当它遍历整个DOM树时,它通常比引用对象的document.forms表示法慢,所以在做很多这样的查找时要考虑到这一点。

document.getElementById() is the recommended way to get reference of elements. It's easier to use and also would not require any changes if you decide to change the Form name or Id. However, as it traverses the entire DOM tree, it is usually slower than the document.forms notation of referencing objects, so take this into account when doing a lot of such look-ups.

document.forms也很难使用,因为您需要知道从文档元素开始的对象的整个路径。

document.forms is also harder to use, as you need you to know the entire path to the object beginning from the document element.

这篇关于document.getElementById(“selAge”)与document.myForms.selAge的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆