javascript - 从弹出窗口提交表单 - javascript

标签 javascript jquery forms

我在父窗口中有一个 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/

相关文章:

javascript - ui.position 相对位置的错误值

javascript - 如果选择/更改了值,则从选择中隐藏/删除选项值

javascript - 如何更改具有相同类名的元素的样式

php - jquery 在两个 View 之间切换

javascript - 在拇指列表上禁用滚动

php - 检测单选表单值集

javascript - Bootstrap 4 中的滚动标签

javascript - 删除本地存储

javascript - 查找填写表格的 URL

javascript - 下拉菜单上的 jQuery val() 返回值 "Array"