使用jQuery选择位于iframe中的表单 [英] Selecting a form which is in an iframe using jQuery

查看:185
本文介绍了使用jQuery选择位于iframe中的表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在jQuery UI对话框中的iframe中有一个表单。该表单包含一个文件输入类型。 jQuery UI对话框包含一个Upload按钮。点击此按钮时,我想以编程方式调用提交方法。我的问题是我如何使用jQuery来选择iframe中的表单。以下代码应该澄清图片:

 < div id =upload_file_picker_dlgtitle =上传文件> 
< iframe id =upload_file_iframesrc =/ frame_src_urlframeborder = 0 width = 100%scrolling = no>< / iframe>
< / div>

frame_src_url包含:

 < form action =/ UploadTaxTableenctype =multipart / form-datamethod =postid =upload-form> 
< p>选择要上传的文件:< / p>
< p>
< input type =filename =datafilesize =60>
< / p>



jQueryUI对话框javascript代码:

  $('#upload_file_picker_dlg')。dialog({
...
buttons:{
'Close':function(){
$(this).dialog('close');
},
'Upload':function(){
$('#upload-form')。submit(); //问题与此行有关
$(this).dialog('close');
}
},
....
});

从上面的javascript代码片断中,我可以如何选择id为 upload-form 位于iframe中,其标识为 upload_file_iframe ???一个iframe是棘手的。
您应该使用以下语法:

  $('#iframeID')。contents()。find(' #上传表单)提交()。 

其中'iframeID'显然是您提供给iframe的ID。



希望它是正确的!

I have a form inside an iframe which is inside a jQuery UI dialog box. The form contains a file input type. The jQuery UI dialog contains an Upload button. When this button is clicked, I would like to programmatically call the submit method. My question is how I could select the form which is in a iframe using jQuery. The following code should clarify the picture:

<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 contains:

<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>

The jQueryUI dialog box javascript code:

$('#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'); 
        }
    },
    ....
});

From the javascript code snippet above, how can I select the form with id upload-form that is in the iframe whose id is upload_file_iframe ?

解决方案

Accessing an element inside an iframe is tricky. You should use the following syntax:

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

where 'iframeID' is obviously an ID you've given to the iframe.

Hope it is correct!

这篇关于使用jQuery选择位于iframe中的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆