0

我想要立即下载按钮来提交表单。我试过了

getElementById("forms").submit();
$("form").submit();
$("#forms").submit();

仍然没有任何效果。

UI 会弹出并执行其他所有操作,但不提交表单

Java 脚本

    $(document).ready(function(){
    $("#dialog-download ").dialog({
        autoOpen: false,
        resizable: false,
        height: 140,
        width: 325,
        modal: true
    });
    $(".opener").click(function(){
        var that = this;
        var checkbox = $(that).next(":checkbox");

        $("#dialog-download").dialog("option", {
            buttons: {
                "Download Now": function(){
                    $(checkbox).prop("checked", !$(checkbox).attr("checked"));
                    $("#dialog-download").dialog("close");
            $("#forms").submit();
                },
                "Download Later ": function(){
                    $(checkbox).prop("checked", !$(checkbox).attr("checked"));
                    $("#dialog-download").dialog("close");
                },
                "Cancel": function(){
                    $("#dialog-download").dialog("close");
                }
            }
        });
        $("#dialog-download").dialog("open");
    });
});

HTML

<div id="dialog-download" title="Download Now?">
    <p><span style="float:left; margin:0 7px 20px 0;"></span>Download the file now or later?</p>
</div>

<form id = "forms" method="post" action="<?php echo $PHP_SELF;?>">
<a class="opener" href="#">db1.csv:</a>
<input id="c1" type="checkbox" name="download[]" value="db1.csv" /><br />
<...>
<input id="submit" type="submit" name="submit" value="submit" >
</form>
4

1 回答 1

1

请参阅 jQuery 文档submit()

表单及其子元素不应使用与表单属性(例如提交、长度或方法)冲突的输入名称或 ID。名称冲突可能会导致令人困惑的失败。有关规则的完整列表并检查这些问题的标记,请参阅DOMLint

http://jsfiddle.net/Fj2cC/4/

于 2012-05-02T13:26:42.870 回答