如何编写脚本以根据 W3C DOM 或 IE 4 DOM 的可用性来使用它们?
htmljavascriptprogramming scripts更新于 2024/5/31 3:24:17
如果您想要编写一个脚本,并能够根据 W3C DOM 或 IE 4 DOM 的可用性灵活地使用它们,那么您可以使用功能测试方法,首先检查方法或属性是否存在,以确定浏览器是否具有您想要的功能。
以下是显示相同的代码片段 −
if (document.getElementById) {
// 如果 W3C 方法存在,则使用它
}
else if (document.all) {
// 如果 all[] 数组存在,则使用它
}
else {
// 否则使用旧版 DOM
}
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

