为什么模拟点击提交不起作用

Why simulate click on submit doesn't work

本文关键字:提交 不起作用 模拟 为什么      更新时间:2023-09-26

我尝试了这个,许多其他仍然不起作用:

我需要在 Filemaker 的 Web 查看器中使用它(MBS( "WebView.RunJavaScript";网络查看器参考;Javascript ))

脚本 : $("#positiveButtonExpand borRad5 jq-picHover").click(function()

在网页上 :

<fieldset>
    <label class="formLabelExpand">Rechercher par numéro de commande :</label>
    <input class="formInputTextMedium resetValue floatLeft borRad5" id="id_1405652204_ScopusIdFilter" name="id_1405652204.ScopusIdFilter" type="text" value="saisissez le n° de la commande">
    <button name="id_1__" type="submit" class="positiveButtonExpand borRad5 jq-picHover">OK</button>
</fieldset>

感谢您的所有回答和建议,没有人为我工作,我认为它来自网站或文件制作者。 :)

positiveButtonExpand是一个类而不是一个ID,你可以选择它.positiveButtonExpand而不是#positiveButtonExpand

$(".positiveButtonExpand").click(function(){
  // code
});

您需要使用以下任一方式选择该按钮:

$(".positiveButtonExpand.borRad5.jq-picHover")

或者更简单地说:

$(".positiveButtonExpand")

我在这里看到的第一件事是你在 ID 上调用处理程序,但在你的 html 中你把它作为一个类。例如:

按钮:class="positiveButtonExpand borRad5 jq-picHover"

Javascript: $("#positiveButtonExpand borRad5 jq-picHover")

Javascript 需要更改为

 $(".positiveButtonExpand").click(function(){})

使用 JQuery 时,如果以"#"开始选择,则表示您正在查找 ID。

最好的方法是模拟真实用户点击。为此,这里有一个简短的脚本。

$.fn.simulateClick = function() {
    return this.each(function() {
        if('createEvent' in document) {
            var doc = this.ownerDocument,
                evt = doc.createEvent('MouseEvents');
            evt.initMouseEvent('click', true, true, doc.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
            this.dispatchEvent(evt);
        } else {
            this.click(); // IE
        }
    });
}

这允许创建一个本机鼠标事件,因此您只需像这样简单地调用函数即可。

$(".positiveButtonExpand").simulateClick();

希望对您有用:)