尝试用greasemonkey模拟点击按钮
我正在尝试编写一个greasemonkey 脚本,通过浏览器更新一组项目的库存。为此,我需要自动填写一些表单并模拟鼠标单击提交按钮。我的表格填写得很好,但我被困在按钮提交上。
这是我试图模拟点击的按钮的 HTML
<input type="submit" value="Find" style="" name="process-form" onclick="imhocaller.value='find-resources-page.left'; imhoaction.value='process-form';">
我尝试做类似的事情,但没有任何运气。
document.getElementsByName('process-form').submit();
如果需要,我可以发布更多代码。谢谢你!
I'm trying to write a greasemonkey script that updates inventory for a collection of items through the browser. To do this I need to autofill a few forms and simulate a mouseclick on the submission button. I have the forms filling out fine, but I'm stuck on the button submission.
Here is the HTML for the button I am trying to simulate clicking
<input type="submit" value="Find" style="" name="process-form" onclick="imhocaller.value='find-resources-page.left'; imhoaction.value='process-form';">
I tried doing something like this, but haven't had any luck.
document.getElementsByName('process-form').submit();
I can post more code if needed. Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
想通了。需要使用 .click() 而不是 .submit()。
我还需要按照 Georgy 的建议添加 [0]。
Figured it out. needed to use .click() instead of .submit().
I also needed to add the [0] as Georgy suggested.
您还可以通过最新的浏览器分派自定义点击事件,并在 IE 中“触发”
onclick
事件。这是最近的一项功能,允许对事件进行大量控制。http://jsfiddle.net/ZWyp7/3/
请注意,您需要监听该事件在发送之前。
You can also dispatch a custom click event via most recent browsers and "fire" an
onclick
event in IE. This is a recent feature that allows tons of control over events.http://jsfiddle.net/ZWyp7/3/
Do note that you need to listen for the event before dispatching it.
试试这个 document.getElementsByName('process-form')[0].submit();
UPD:对!必须是 .click() 而不是 .submit()
try this document.getElementsByName('process-form')[0].submit();
UPD: Right! Must be .click() and not .submit()
在这里你尝试提交一个输入,你必须提交表单。因此,如果您标记为 #myForm 的 id,则需要执行以下操作:
document.getElementById('myForm').submit()
Here you try to submit a input, you have to submit the form. So if you tag as an id of #myForm you need to do :
document.getElementById('myForm').submit()
另一种方法是在 JQuery 中使用
.trigger( "submit" )
。Another way to do it is to use
.trigger( "submit" )
in JQuery.