jQuery iframe 表单提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3407276/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery iframe form submit
提问by Lee
Is there any way to submit an iframed form from jQuery? What I have is the following:
有没有办法从 jQuery 提交 iframe 表单?我所拥有的是以下内容:
$('button#bookingButton').click(function(){
$('<iframe id="externalSite" class="externalSite" src="/form/page" />').dialog({
title:'Form',
autoOpen: true,
width: 800,
height: 600,
modal: false,
resizable: false,
buttons:{
'Close':function(){$(this).dialog("close");},
'Add Booking':function(){$('form#bookingForm').submit();}
}
}).width(800 - 25);
});
This creates a jQuery ui dialog which has an iframe within it. This works fine and the regular submit button works fine however the jQuery button does not submit the form.
这将创建一个 jQuery ui 对话框,其中包含一个 iframe。这工作正常,常规提交按钮工作正常,但 jQuery 按钮不提交表单。
回答by Bob Gregor
add this AFTER you insert the IFRAME into the DOM:
在将 IFRAME 插入 DOM 后添加:
$("#externalSite").contents().find('form').submit()