Chrome 开发者控制台问题
我正在尝试测试我的网站上产生随机整数的功能。我想知道是否可以使用 chrome 开发者控制台通过代码触发按钮事件,而无需实际按下页面上的按钮。是否可以发送与用户输入文本框中的值不同的值。假设用户将他的名字输入“Tom”,有没有办法通过控制台中的代码触发按钮事件以及更改用户输入以进行测试。
I'm trying to test a feature on my website that produces a random integer. I was wondering if it was possible to use the chrome developer console to trigger a button event with code, without physically pressing the button on the page. Also is it possible to send a different value than what the user put into my textbox. Let's say the user puts his name in "Tom", is there a way to trigger the button event via code in the console as well as change that user input for testing purposes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在控制台中运行(几乎)任何您想要的 JavaScript 代码,并且它将在页面的上下文中执行。例如,要模拟单击按钮,您可以键入并运行:
这将单击页面上找到的第一个按钮。显然,你可以通过这种方式改变任何字段中的任何值,但我不完全理解你期望如何做到这一点 - 你想绕过用户,但用户不会坐在 Chrome 前面,你的控制台想要使用吗?
You can run (almost) whatever JavaScript code you want in the console, and it will execute in the context of the page. For instance, to emulate a click on the button, you can type and run:
which will click the first button found on the page. You can obviously change whatever value in whatever field this way, but I don't fully understand how you expect to do that - you want to bypass the user, but won't the user be sitting in front of Chrome, whose console you'd like to use?