简体   繁体   English

如何从Chrome开发者控制台访问w3school页面上的元素?

[英]How to access elements on w3school pages from Chrome developer console?

I would like to experimenting with onfocus event on page: http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onfocus 我想在页面上试验onfocus事件: http//www.w3schools.com/jsref/tryit.asp? filename = tryjsref_onfocus

I use Chrome developer console (Ctrl+Shift+I). 我使用Chrome开发者控制台(Ctrl + Shift + I)。 When I try to access the input element by typing in the console: 当我尝试通过在控制台中输入来访问输入元素时:

document.getElementsByTagName("input")

I get two hidden input elements instead of the text input element. 我得到了两个隐藏的输入元素,而不是文本输入元素。 Screenshot image: http://i.imgur.com/zGBsZWY.png So What's going on here, and how can access those elements on the "tryout" pages? 截图图片: http//i.imgur.com/zGBsZWY.png那么这里发生了什么,以及如何在“试用”页面上访问这些元素?

@David is right, each iframe is a separate javascript context. @David是正确的,每个iframe是一个单独的JavaScript上下文。

If you want to execute javascript in context of an iframe, see this question 如果要在iframe的上下文中执行javascript,请参阅此问题

Alternatively, you can use element picker of Chrome Dev Tools (ctrl-shift-c) and then in console type $0 , it will return the last focused element. 或者,您可以使用Chrome Dev Tools的元素选择器(ctrl-shift-c),然后在控制台类型$0 ,它将返回最后一个聚焦元素。 When you then focus something else, you can use $0 to the newly focused element, $1 for previously focused one etc. 当你关注其他东西时,你可以使用$0到新聚焦的元素, $1用于之前关注的元素等。

See Dev Tools command line API 请参阅开发工具命令行API

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM