代码之家  ›  专栏  ›  技术社区  ›  Kevin Le - Khnle

使用jquery选择iframe中的表单

  •  6
  • Kevin Le - Khnle  · 技术社区  · 16 年前

    我在jQueryUI对话框中的iframe中有一个表单。表单包含文件输入类型。jQueryUI对话框包含一个上载按钮。单击此按钮时,我希望以编程方式调用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为的表单 上传表单 在ID为的iframe中 上传文件名 ?

    3 回复  |  直到 16 年前
        1
  •  16
  •   Davide    16 年前

    访问iframe中的元素很困难。 您应该使用以下语法:

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

    其中“iframe id”显然是您提供给iframe的ID。

    希望是正确的!

        2
  •  2
  •   Kevin Le - Khnle    16 年前

    答案是:

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

    我从中学到的 http://simple.procoding.net/2008/03/21/how-to-access-iframe-in-jquery/

        3
  •  0
  •   zynx    16 年前

    在我的头上,我想说您可能需要将逻辑添加到iframe源所在的文件中。

    推荐文章