我如何编写一个脚本,根据其可用性使用W3C DOM或IE 4 DOM?

原创
ithorizon 5个月前 (10-19) 阅读数 39 #HTML

如果您希望编写一个能够根据其可用性灵活地使用 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
}

以上就是我如何编写一个脚本,根据其可用性使用W3C DOM或IE 4 DOM?的详细内容,更多请关注IT视界其它相关文章!



热门