在 Chrome JavaScript 控制台中测试 jQuery 语句

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3821703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 16:09:59  来源:igfitidea点击:

testing jQuery statements in Chrome JavaScript console

jquerygoogle-chrome

提问by damir

I'm trying to change a checkbox value from chrome JavaScript console. I'm aware that changes are printed to object and not on screen. I'd like to execute a jQuery statement, i.e.:

我正在尝试从 chrome JavaScript 控制台更改复选框值。我知道更改会打印到对象而不是屏幕上。我想执行一个 jQuery 语句,即:

('input[name=foo]').attr('checked', true);

Is there any way to enter a jQuery statement, and and see changes instantly in the page?

有什么方法可以输入 jQuery 语句,并在页面中立即查看更改吗?

回答by Santeri Vesalainen

Yeah, and even if you don't have jquery available let it be :)

是的,即使你没有 jquery 可用,让它成为 :)

Edited snippet from How can I use jQuery in Greasemonkey scripts in Google Chrome?

编辑段从我如何在谷歌浏览器Greasemonkey脚本使用jQuery?

var script = document.createElement("script");
  script.setAttribute("src", "https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js");
  script.addEventListener('load', function() {
    var script = document.createElement("script");
    document.body.appendChild(script);
  }, false);
  document.body.appendChild(script);

After this go.

这走后。

回答by Anurag Uniyal

In chrome console you can do run any JavaScript, so if page has jQuery loaded, you can access the element and check/uncheck it e.g. stackoverflow.com (this site) uses jQuery so I can just access answer textarea and enter a value, try this

在 Chrome 控制台中,您可以运行任何 JavaScript,因此如果页面加载了 jQuery,您可以访问该元素并选中/取消选中它,例如 stackoverflow.com(此站点)使用 jQuery,因此我可以访问答案 textarea 并输入一个值,请尝试这个

$('#wmd-input').val('This is my answer') 

So you can do anything which is possible in jQuery.

所以你可以做任何在 jQuery 中可能的事情。

回答by Shikiryu

If you got jQuery loaded in the current page, you can type jQuery command.

如果你在当前页面加载了 jQuery,你可以输入 jQuery 命令。

Just type $('input[name=foo]').attr('checked', true);or whatever should work in jQuery and press enter.

只需键入$('input[name=foo]').attr('checked', true);或任何应该在 jQuery 中工作的内容,然后按 Enter。

回答by sje397

$('input[name=foo]').click();

does the same thing as clicking with your mouse.

和用鼠标点击一样。