本文介绍了document.getElementById(& quot; someId& quot)).someId的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这个问题看似愚蠢,但是使用document.getElementById("someId")Vs访问元素(ID为"someId")之间有什么区别?只需输入someId即可?
This question might seem silly, but what's the difference between accessing an element (with id "someId") using document.getElementById("someId") Vs. just typing someId ?
例如:
document.getElementById("someId").style.top = "12px";
vs
someId.style.top = "12px";
这是示例代码 http://jsfiddle.net/pRaTA/(我发现它没有在Firefox中不能正常工作
Here's a sample code http://jsfiddle.net/pRaTA/ (I found that it doesn't work in firefox)
推荐答案
区别在于,虽然 someId
在某些浏览器中有效,但 document.getElementById("someId")
实际上符合W3C标准.
The difference is that while someId
works in some browsers, document.getElementById("someId")
actually complies with the W3C standard.
这篇关于document.getElementById(& quot; someId& quot)).someId的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!