如何编写一个脚本以便根据其可用性使用 W3C DOM 或 IE 4 DOM?
如果你想编写一个脚本,该脚本可以灵活使用 W3C DOM 或 IE 4 DOM(取决于它们的可用性),那么你可以使用一个功能测试方法,该方法首先检查方法或属性的存在,以确定浏览器是否具备你期望的功能。
以下是显示相同内容的代码片段 −
if (document.getElementById) {
// If the W3C method exists, use it
}
else if (document.all) {
// If the all[] array exists, use it
}
else {
// Otherwise use the legacy DOM
}
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP