Mar*_*rko 25 iframe jquery jquery-ui jquery-ui-dialog
我已经实现了以下代码,用于在jQuery对话框中上传照片(使用iframe).
这是Iframe
<div style="display: none">
<iframe id="upload-form" frameborder="0" marginheight="0" marginwidth="0" src="Upload.aspx"></iframe>
</div>
Run Code Online (Sandbox Code Playgroud)
这是父页面上的jQuery代码,它负责打开对话框.
$("#upload-image").click(function (e) {
e.preventDefault();
$('#upload-form').dialog({
modal: true,
width: 300,
title: "Upload Image",
autoOpen: true,
close: function(event, ui) { $(this).dialog('close') }
});
});
Run Code Online (Sandbox Code Playgroud)
然后我在上传成功后注入脚本(在iframe页面上),将结果传递回父页面,但我想同时关闭对话框.
$(document).ready(function () {
$(parent.document).find('#imagePathValue').val('theimagevalue');
$(parent.document).find('#upload-form').dialog('close');
});
Run Code Online (Sandbox Code Playgroud)
该#imagePathValue表被成功过去了,但我似乎无法能够关闭对话框.
有任何想法吗?
mik*_*r87 40
为了使其工作,您必须从父级调用jQuery,而不是从iframe调用.为此,请使用以下...
window.parent.jQuery('#upload-form').dialog('close');
Run Code Online (Sandbox Code Playgroud)
应该这样做!
试试这个:
$(document).ready(function () {
$(parent.document).find('#imagePathValue').val('theimagevalue');
window.parent.$('#upload-form').dialog('close');
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
27613 次 |
| 最近记录: |