简体   繁体   English

如果不首先使用 Chrome 开发工具检查元素,则无法 select 谷歌 Chrome 控制台中的 DOM 元素

[英]Cannot select a DOM element in Google Chrome Console without inspecting the element first using Chrome Dev Tools

I run into something really strange with Google Chrome Dev Console.我在使用 Google Chrome Dev Console 时遇到了一些非常奇怪的事情。

Firstly I reload my page ( ctrl + F5 ), then I launch Google Chrome Dev console ( F12 ) and try to type in首先我重新加载我的页面( ctrl + F5 ),然后我启动 Google Chrome 开发控制台( F12 )并尝试输入

document.getElementById('myElement')

to which Chrome's console responds with: Chrome 控制台的响应是:

null

It's weird because I can actually see my element on the page and after I inspected the element using Chrome Dev Tools (right click on the element and choose Inspect ) and switched back into the Console tab and typed again: document.getElementById('myElement') I finally got a correct result:这很奇怪,因为我实际上可以在页面上看到我的元素,并且在我使用 Chrome 开发工具检查了元素之后(右键单击元素并选择Inspect )并切换回控制台选项卡并再次输入: document.getElementById('myElement')我终于得到了正确的结果:

<input type="text" id="myElement" class="urEdf2Txt" autocomplete="off" size="10" maxlength="6" value="1.39" />

Note: I always waited until the page is fully loaded and waited until the element is fully visible before trying the procedure described above.注意:在尝试上述过程之前,我总是等到页面完全加载并等到元素完全可见。

this normally happens on iframe .这通常发生在iframe上。 try to see if the target element is in an iframe in the page.尝试查看目标元素是否在页面中的iframe中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Chrome开发工具中的选择元素不起作用? - Select element in Chrome Dev Tools not working? 无法使用Chrome开发工具检查元素 - Unable to Inspect an Element using Chrome Dev Tools Chrome开发工具:从bookmarklet / Snippet访问DOM元素$ 0指针 - Chrome dev tools: Accessing the DOM element $0 pointer from bookmarklet/Snippet 为什么从带有 javascript 的模板中看不到乘法的结果,但在 chrome 开发工具中检查元素时却看到了? - Why is the result of the multiplication not seen from the template with javascript but when inspecting the element in chrome dev tools it is? Chrome Dev Tools 控制台 - 以编程方式选择框架 - Chrome Dev Tools console - select frame programmatically 如何在使用 chrome 开发工具时保持元素显示在 HTML 中 - How to keep an element displayed in HTML while using chrome dev tools JavaScript document.querySelector() 在 Chrome 开发工具中登录到控制台时不显示标签/元素 - JavaScript document.querySelector() not showing tag/element when logged to console in Chrome Dev Tools Chrome 扩展程序无法选择 DOM 元素 - Chrome extension unable to select DOM element 检查 Google Chrome 扩展中的 DOM 元素 - Check DOM element in Google Chrome Extension Chrome 开发工具:如何查看 HTML 元素的附加事件侦听器 - Chrome dev tools: How to see attached event listeners for an HTML element
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM