我想使用工具栏 (Firefox) 中的脚本(使用 JavaScript)填充表单中的输入。
示例:(我使用 Google 输入)
<input type="text" name="q" />
我的脚本:
javascript:(document.getElementsByName("q")[0].value = "New Value");
但是,当我单击工具栏中的按钮时,脚本不会直到输入(在 Google 上),只需打开一个包含“新值”的页面。
可以这样做吗?如果是,我该怎么办?
最佳答案
将脚本包装在 anonymous function 中将其与页面上当前的代码隔离。
javascript:(function(){document.getElementsByName("q")[0].value%20=%20"New%20Value";})();
关于javascript - 在我的工具栏中用脚本填充 <input>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36611391/