如何编写脚本以根据 W3C DOM 或 IE 4 DOM 的可用性来使用它们?
htmljavascriptprogramming scripts更新于 2024/6/24 10:03:00
如果您想要编写一个脚本,并能够根据 W3C DOM 或 IE 4 DOM 的可用性灵活地使用它们,那么您可以使用功能测试方法,首先检查方法或属性是否存在,以确定浏览器是否具有您想要的功能。
以下是显示相同的代码片段 −
if (document.getElementById) { // 如果 W3C 方法存在,则使用它 } else if (document.all) { // 如果 all[] 数组存在,则使用它 } else { // 否则使用旧版 DOM }