jquery-ui – 使用jQuery选择iframe中的表单

我在iframe中有一个表单,它位于jQuery UI对话框中.表单包含文件输入类型. jQuery UI对话框包含一个Upload按钮.单击此按钮时,我想以编程方式调用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上的表单?

解决方法

访问iframe中的元素很棘手.
您应该使用以下语法:
$('#iframeID').contents().find('#upload-form').submit();

其中’iframeID’显然是您为iframe提供的ID.

希望它是正确的!

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...