我在jQuery UI对话框内的iframe中有一个表单。该表单包含文件输入类型。 jQuery UI对话框包含一个“上传”按钮。单击此按钮后,我想以编程方式调用Submit方法。我的问题是如何使用jQuery选择iframe中的表单。以下代码应使图片更清晰:

<div id="upload_file_picker_dlg" title="Upload file">
    <iframe id="upload_file_iframe" src="/frame_src_url" frameborder=0 width=100% scrolling=no></iframe>
</div>

frame_src_url包含:
<form action="/UploadTaxTable" enctype="multipart/form-data" method="post" id="upload-form">
<p>Select a file to be uploaded:</p>
<p>
    <input type="file" name="datafile" size="60">
</p>

jQueryUI对话框的javascript代码:
$('#upload_file_picker_dlg').dialog({
    ...
    buttons: {
        'Close': function() {
            $(this).dialog('close');
        },
        'Upload': function() {
            $('#upload-form').submit(); //question is related to this line
            $(this).dialog('close');
        }
    },
    ....
});

从上面的javascript代码段中,如何选择ID为 upload_file_iframe 的iframe中ID为 upload-form 的表单?

最佳答案

访问iframe中的元素非常棘手。
您应该使用以下语法:

$('#iframeID').contents().find('#upload-form').submit();

其中“iframeID”显然是您赋予iframe的ID。

希望它是正确的!

关于jquery-ui - 使用jQuery选择iframe中的表单,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2953436/

10-12 12:20
查看更多