【发布时间】:2011-05-22 11:39:12
【问题描述】:
我已经实现了以下代码,用于在 jQuery 对话框中上传照片(使用 iframe)。
这是 iframe
<div style="display: none">
<iframe id="upload-form" frameborder="0" marginheight="0" marginwidth="0" src="Upload.aspx"></iframe>
</div>
这是父页面上负责打开对话框的 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') }
});
});
然后我在上传成功后注入一个脚本(在 iframe 页面上),将结果传递回父页面,但我想同时关闭对话框。
$(document).ready(function () {
$(parent.document).find('#imagePathValue').val('theimagevalue');
$(parent.document).find('#upload-form').dialog('close');
});
#imagePathValue 传递成功,但我似乎无法关闭对话框。
有什么想法吗?
【问题讨论】:
标签: jquery jquery-ui iframe jquery-ui-dialog