DOM click()在此按钮上不起作用 [英] DOM click() is not working on this button
问题描述
当我使用方法 click()
单击按钮时,提交失败。
但是,当我使用鼠标单击按钮时在该网页上(提交形式相同)。
When I use method click()
to click the button, the submission failed.
But, when I use the mouse to click the button on that webpage, (the submit form is same) it works.
HTML文件:
<button xmlns="http://www.w3.org/1999/xhtml" class="ui-button button1" type="submit" id="create">
<span>
<span>Create</span>
</span>
</button>
我的用户脚本文件:
document.getElementById("create").click();
如何使用HTML DOM click()单击按钮?
How do I click the button using HTML DOM click()?
推荐答案
click方法并不总是有效。尝试发送与此答案类似的点击
事件:
The click method does not always work. Try sending a click
event similarly to this answer:
var targBtn = document.querySelector ("#create");
var clickEvent = document.createEvent ('MouseEvents');
clickEvent.initEvent ('click', true, true);
targBtn.dispatchEvent (clickEvent);
但也请注意,该按钮可能无法操作点击。请参见在AJAX驱动的网站上选择和激活正确的控件 。
该按钮可能在鼠标按下
,鼠标或事件的某种组合。使用该问题中的技术来激活控件。 如果无法正常工作,请链接到目标页面。
The button may operate on mousedown
, mouseup
, or some combination of events. Use the techniques from that question to activate the control. Link to the target page if you can't get it to work.
这篇关于DOM click()在此按钮上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!