有人可以介绍一下为什么使用NAME与表单元素交互已经不再实践,并且document.getElementById
已经取代了它的历史/原因吗?
到底发生了什么历史事件促使这种变化和转变呢?
最后,是否存在转变或两者仍然是推荐的操作方式?
Document.getElementById vs document.form.name
根据一些论坛讨论,document.form.name在某些浏览器中无法识别。这是否属实?参见:
"I've been told in the past that you should not use "document.form_name.element_name" compared to "document.getElementById()", as the first is not recognized by all browsers. "
这个论坛中的一个讨论讨论了在JavaScript中使用document.getElementById()和document.formName.element的差异。使用document.getElementById()是更好的选择,因为它可以更直接地找到所需的元素,并且比document.formName.element更快和更安全,特别是在有多个表单时。