getElementById在哪里定义

getElementById在哪里定义

本文介绍了方法document.getElementById在哪里定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:这仅是出于学习目的.

console.log(this);
document.getElementById = function(){
    alert('testing');
}

document.getElementById('someID');

我已经编写了上面的javascript代码.当我加载页面时,它会显示一个警告框,显示正在测试".

I have the above piece of javascript code written. When I load the page it shows an alert box saying 'Testing'.

所以我猜想getElementByIddocument对象的一种方法,并且已经将其覆盖为alert('testing'),这就是为什么它在页面加载时向我显示警告框的原因.

So I am guessing getElementById is a method of the document object and I've overwritten it to alert('testing'), which is why its showing me the alert box when the page loads.

如果该部分是正确的,那么在下面展开document对象时我是否应该看不到getElementById?我在错误的地方寻找东西吗?

If that part is correct, shouldn't I see the getElementById when I expand the document object below? Am I looking for it in the wrong place or something?

推荐答案

您的方法就在其中.只是Chrome决定不向您显示.

Your method is in there. It's just Chrome decided not to show you.

但是,是否应该这样做是另一个问题.

Whether you should do this, however, is another question of its own.

这篇关于方法document.getElementById在哪里定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 05:55