jquery 对话框在 iframe 中提交表单
我正在使用 jquery 打开一个包含 iframe 的对话框(不要问!)。我想在关闭对话框时在 iframe 中提交表单,但它不起作用。
我可能犯了一个简单的错误(我对 jquery 还很陌生),但这个问题一直让我陷入困境。
这是我的代码:
$(function() {
$( "#iframe" ).dialog({
modal: true,
autoOpen: false,
height: 500,
width: 700,
buttons: {
"Save and close": function() {
$( "#iframe").contents().find("#contentform").submit();
$( "#iframe" ).dialog( "close" );
},
Cancel: function() {
$( "#iframe" ).dialog( "close" );
}
}
});
$( "#openProfile" ).click(function() {
$( "#iframe" ).dialog( "open" );
$('#iframe').attr('src','file.asp');
return false;
});
});
但是,如果我这样做而不是提交表单:
"Save and close": function() {
var myformvalue = $( "#iframe").contents().find("#formfield").val();
alert(myformvalue);
$( "#iframe" ).dialog( "close" );
}
...它会返回正确的值,所以我知道它正在识别我的表单及其值。
预先感谢您的帮助。
I'm using jquery to open a dialog containing an iframe (don't ask!). I want to submit the form in the iframe on closing the dialog but it isn't working.
I'm probably making a simple error (I'm quite new to jquery) but this problem has been driving me round the bend.
Here is my code:
$(function() {
$( "#iframe" ).dialog({
modal: true,
autoOpen: false,
height: 500,
width: 700,
buttons: {
"Save and close": function() {
$( "#iframe").contents().find("#contentform").submit();
$( "#iframe" ).dialog( "close" );
},
Cancel: function() {
$( "#iframe" ).dialog( "close" );
}
}
});
$( "#openProfile" ).click(function() {
$( "#iframe" ).dialog( "open" );
$('#iframe').attr('src','file.asp');
return false;
});
});
However, if I do this instead of submitting the form:
"Save and close": function() {
var myformvalue = $( "#iframe").contents().find("#formfield").val();
alert(myformvalue);
$( "#iframe" ).dialog( "close" );
}
...it returns the correct value so I know it is recognising my form and its values.
Thanks in advance for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您遇到了 jQuery V1.10(/9?) 问题,他们对其进行了更改,以便将对话框容器移出 DOM,这样您最终就不会从 iFrame 中的页面获得回发。参考此:https://stackoverflow.com/a/24663205/3334255和ASP.NET 按钮单击事件未触发
I think you are running up against the jQuery V1.10(/9?) issue where they changed it so that the dialog container is moved out of the DOM, so you don't end up getting postbacks from the page in the iFrame. Reference this: https://stackoverflow.com/a/24663205/3334255 and An ASP.NET button click event is not firing