我在父窗口中有一个 FORM,
<form id="myform">
<username>
<password>
</form>
在 jQuery 中
$("#myform").submit(function(e){
e.preventDefault(); // prevent default form submit
//some of my other codes ...
});
我正在使用 window.open
打开一个新窗口
var popupWindow = window.open("myUrl");
我正在尝试从弹出窗口提交 myform
表单
$(window.opener.document.getElementById("myform")).submit();
表单正在提交,但问题是它使用默认表单提交而不是我的附加事件。
我做错了什么?
请帮帮我。 谢谢。
最佳答案
这就是我的工作:
Parent.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<input type="button" value="Try Me..." onclick='window.open("Child.html");' />
<form action="post.html" method="post" id="myForm">
</form>
</body>
</html>
Child.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script>
function submitParent() {
window.opener.document.forms["myForm"].submit();
window.close();
}
</script>
</head>
<body>
<input type="button" onclick="submitParent();" value="Submit Parent" />
</body>
</html>
当点击“提交父项”时,它会关闭子项,并将父项提交给“Post.html”。
祝你好运!
关于javascript - 从弹出窗口提交表单 - javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13926973/