JavaScript - 如何为其他浏览器添加对document.all的支持?

JavaScript - 如何为其他浏览器添加对document.all的支持?

问题描述:

我有一堆旧的Javascript代码,其中使用document.all。所以现在,我需要找到一种方法来取代document.alldocument.getElementById。是否有什么我可以封装document.all,所以它会调用第二个函数?或者我需要编辑所有文件?JavaScript - 如何为其他浏览器添加对document.all的支持?

+7

从长远来看,如果您刚刚更换它,将会容易得多。不要低估查找/替换文本编辑器的能力。 – Ian 2013-04-25 14:43:22

+2

只要咬下子弹就可以取而代之。 'document.all'已经过时很长时间了。 – Spudley 2013-04-25 14:44:19

+0

'document.all'似乎仍然存在(和工作)在谷歌浏览器。 – 2013-04-25 14:44:44

if (!document.all) { 
    document.constructor.prototype.__defineGetter__('all', function() { 
     return document.getElementsByTagName('*'); 
    }); 
} 
+1

如何使用诸如'document.all ['header']'? – bfavaretto 2013-04-25 14:48:53

+0

(以上我的意思是“标题”是一个id或名称,而不是标签名称) – bfavaretto 2013-04-25 14:57:43