JS:如何使document.getElementById跨浏览器? [英] JS: How to make document.getElementById cross-browser?
本文介绍了JS:如何使document.getElementById跨浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
document.getElementById 似乎并不适用于所有浏览器(我的意思是一些旧的),我相信有开发人员不知道这一点。
document.getElementById doesn't seem to work across all browsers (I mean some old ones) and I am sure there are developers who are not aware of this.
您会建议哪些解决方案使其成为跨浏览器?
What solutions would you suggest to make it cross-browser?
谢谢
推荐答案
如果document.getElementById不起作用,那么:
If document.getElementById doesn't work then either:
- 你做错了(无效的HTML,尝试访问名称而不是ID等)
或
- 您正在使用Netscape 4.x和Internet Explorer 4.x
有三种方式来处理这个时代的浏览器。
There are three ways to deal with browsers of this era.
- 告诉人们升级。对于用户和作者来说,它们都是不安全的,安全漏洞的恶梦。
- 建立在工作的东西,并确保您的JS检查存在
getElementById
和朋友之前尝试使用它们(if(!document.getElementById){return false; / * DOM不满足于JS这里* /}
) - 了解
document.all
和document.layers
- Tell people to upgrade. They are unmaintained, security hole ridden nightmares for user and author alike.
- Build on stuff that works and make sure your JS checks for the existence of
getElementById
and friends before trying to use them (if (!document.getElementById) { return false; /* Insufficient DOM to bother with JS here */ }
) - Learn about
document.all
anddocument.layers
这篇关于JS:如何使document.getElementById跨浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文