我已经实现了以下代码,用于在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
被成功传递,但我似乎无法关闭对话框。
有任何想法吗?