javascript - document.getElementById 方法在哪里定义?

标签 javascript html

注意:这仅用于学习目的..

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

document.getElementById('someID');

我已经编写了上面的一段 javascript 代码。当我加载页面时,它会显示一个警告框,上面写着“测试”。

所以我猜测 getElementByIddocument 对象的一个​​方法,我已经将它覆盖为 alert('testing'),这就是它在页面加载时向我显示警告框的原因。

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

enter image description here

最佳答案

你的方法就在那里。只是 Chrome 决定不向您展示。

然而,您是否应该这样做是另一个问题。

关于javascript - document.getElementById 方法在哪里定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46478476/

相关文章:

javascript - XMLHttpRequest 无法加载 "THIS URL"来源 http ://localhost:3000 is not allowed by Access-Control-Allow-Origin.

JavaScript/正则表达式 : Remove text between parentheses

html - Tag Helper 中的 MVC Core HTML Bootstrap 按钮

javascript - 表分页 [Bootstrap - Django]

javascript - 如果选中 radio1 则显示 div1,如果选中 radio2 则显示 div2

html - 为什么CSS动画要产生渐变?

javascript - Highcharts 列适合/调整图表

javascript - JS HTML5 拖放 : Custom Dock Effect Jumping Around in Chrome

javascript - 将脚本放入脚本中

html - 通过 css/bootstrap 使用动态弹出窗口