jjzjj

chocolat

全部标签

javascript - 为什么 window[id] === document.getElementById( id )

这个问题在这里已经有了答案:Isthereaspecthattheidofelementsshouldbemadeglobalvariable?(5个答案)关闭8年前。我注意到在一些浏览器中,dom元素可以通过它们的id来访问,就像这样:HTMLJSalert(chocolat.id);//alerts"chocolatchocolat;//pointstothenodewindow.chocolat;//idemchocolat===document.getElementById('chocolat');//true(在这里测试:http://jsfiddle.net/GUUPT/)