【发布时间】:2011-06-22 10:57:46
【问题描述】:
为什么这不起作用?
function foo() {
var g = document.getElementById;
g('sampleID');
}
Chrome 中抛出此错误:Uncaught TypeError: Illegal invocation
...在 Firefox 中:Error: uncaught exception: [Exception... "Illegal operation on WrappedNative prototype object"
它可以在 IE9 beta 中运行!!
【问题讨论】:
-
你试过了吗,
g.call(document, 'sampleID');?? -
@Pointy 不,我没有提前考虑 :)
-
@Pekka 我投票决定关闭它。那样可以么?我不想删除它,因为我担心它会从我的问题列表中删除,我想保留这个问题。
-
@Šime 是的,绝对!您的示例比另一个问题中的示例方式好,请保留此示例。
标签: javascript