在Chrome中“现场”执行Javascript代码?

时间:2022-09-11 07:25:09

I have a page in chrome which contains many textboxes and I wish to feed values automatically to them. I already have the list of name-value pairs, so if I could simple execute a series of Javascript commands on the form "document.getElementsByName(NAME)[0].value = VALUE;" I'll be done (I hope...)

我有一个chrome页面,其中包含许多文本框,我希望自动为它们提供值。我已经有了名称 - 值对的列表,所以如果我可以在表单“document.getElementsByName(NAME)[0] .value = VALUE;”上简单地执行一系列Javascript命令。我会完成的(我希望...)

So the question is - can I run a JS code "on the spot", or do I have to use a content script somehow?

所以问题是 - 我可以“当场”运行JS代码,还是我必须以某种方式使用内容脚本?

5 个解决方案

#1


44  

Right click on the page and choose 'inspect element'. In the screen that opens now (the developer tools), clicking the second icon from the left @ the bottom of it opens a console, where you can type javascript. The console is linked to the current page.

右键单击页面并选择“检查元素”。在现在打开的屏幕(开发人员工具)中,单击左侧第二个图标@底部会打开一个控制台,您可以在其中键入javascript。控制台链接到当前页面。

#2


5  

I'm not sure how far it will get you, but you can execute JavaScript one line at a time from the Developer Tool Console.

我不确定它能带给你多少,但你可以从Developer Tool Console一次执行一行JavaScript。

#3


2  

You can use bookmarklets if you want run bigger scripts in more convenient way and run them automatically by one click.

如果您想以更方便的方式运行更大的脚本并通过一次单击自动运行它们,您可以使用bookmarklet。

#4


1  

If you mean you want to execute the function inputted, yes, that is simple:

如果你的意思是你想要执行输入的功能,是的,这很简单:

Use this JS code:

使用这个JS代码:

eval(document.getElementById( -- el ID -- ).value);

#5


-3  

Have you tried something like this? Put it in the head for it to work properly.

你尝试过这样的事吗?把它放在头脑中让它正常工作。

<script type="text/javascript">
    document.addEventListener("DOMContentLoaded", function(){
         //using DOMContentLoaded is good as it relies on the DOM being ready for
         //manipulation, rather than the windows being fully loaded. Just like
         //how jQuery's $(document).ready() does it.

         //loop through your inputs and set their values here
    }, false);
</script>

#1


44  

Right click on the page and choose 'inspect element'. In the screen that opens now (the developer tools), clicking the second icon from the left @ the bottom of it opens a console, where you can type javascript. The console is linked to the current page.

右键单击页面并选择“检查元素”。在现在打开的屏幕(开发人员工具)中,单击左侧第二个图标@底部会打开一个控制台,您可以在其中键入javascript。控制台链接到当前页面。

#2


5  

I'm not sure how far it will get you, but you can execute JavaScript one line at a time from the Developer Tool Console.

我不确定它能带给你多少,但你可以从Developer Tool Console一次执行一行JavaScript。

#3


2  

You can use bookmarklets if you want run bigger scripts in more convenient way and run them automatically by one click.

如果您想以更方便的方式运行更大的脚本并通过一次单击自动运行它们,您可以使用bookmarklet。

#4


1  

If you mean you want to execute the function inputted, yes, that is simple:

如果你的意思是你想要执行输入的功能,是的,这很简单:

Use this JS code:

使用这个JS代码:

eval(document.getElementById( -- el ID -- ).value);

#5


-3  

Have you tried something like this? Put it in the head for it to work properly.

你尝试过这样的事吗?把它放在头脑中让它正常工作。

<script type="text/javascript">
    document.addEventListener("DOMContentLoaded", function(){
         //using DOMContentLoaded is good as it relies on the DOM being ready for
         //manipulation, rather than the windows being fully loaded. Just like
         //how jQuery's $(document).ready() does it.

         //loop through your inputs and set their values here
    }, false);
</script>

相关文章