jQuery函数.submit()不工作

jQuery function .submit() not working

本文关键字:工作 函数 submit jQuery      更新时间:2024-04-14

无法真正弄清楚为什么此代码不起作用。

我从MySQL查询中创建了一个链接列表,并对它们进行分类,以在单击时打开jQuery对话框。以下是我如何生成链接和所有脚本内容:

$(function(){
    $( "#select" ).dialog({
        autoOpen: false,
        width: 280,
        modal: true,
        resizable: false,
        },
        buttons: [{
            text: "Close",
            click: function() {
            $( this ).dialog( "close" );
            }
        }]
    });
    $( ".perm" ).click(function() {
        $("#select").dialog("open");
        $("#cod").val(this.id);
        $("#pass").submit();
    });
});
//And then generating links
echo "<a id='"".$fetch['id']."'" href='"#'" class='"perm'">Click me</a>'n";

还有一个包含iFrame的div,它将被打开到对话框中,并且应该能够通过表单将jQuery函数提交的隐藏值读取到div中。

<div id="select" title="Blabla">
    <form id="pass" target="iframe" method="post" action="permcom.php">
        <input type="hidden" name="idcom" id="cod" value="">
    </form>
    <iframe id="permcom" name="iframe" src="permcom.php"></iframe>
</div>

我也尝试过使用event.preventDefault();,但什么也没发生。对话框打开,正确显示iFrame,但在POST阵列中找不到任何数据。

我唯一的目的是通过POST将触发函数的元素的id发送到iFrame,以便在不关闭或刷新页面的情况下进行其他操作。

我哪里错了?

您不能正常使用jQuery来访问iframe的内容。此外,我不知道你的表格在做什么。这是完全错误的。您可以使用AJAX发送POST数据,在iframe内部或外部发送,但不能将表单发送到iframe中。这没有任何意义。

假设表单位于iframe内部,则需要执行以下操作:

$("#permcom").contents().find("#the-form").submit();

因此,您可以访问iframe中的元素,而不是使用普通的表单提交。你需要四处乱搞。