如何编写脚本根据可用性使用 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