我有一个常规的 POST 表单。我有 2 个提交按钮,一个称为“提交”,另一个称为“预览”。
我想要做的是,当单击提交按钮时,我希望在同一窗口中定期提交表单。但是,当单击预览时,我希望更改表单的操作 URL,并在新窗口中打开它。例如:
$("#myForm").attr('action', 'http://new-url.com')
.attr('target', '_BLANK');
$("#myForm").submit();
在新的弹出窗口打开后,我希望恢复旧的操作/目标属性,因此如果单击提交按钮,它将被提交到常规网址。
如何做到这一点?
最佳答案
<form onsubmit="this.action = 'http://old-url.com'; this.target = '_self';">
<input type="submit" value="Submit"> <!-- This triggers the onsubmit that resets the action and target -->
<input type="button" value="Preview" onclick="this.form.action = 'http://new-url.com'; this.form.target = '_blank'; this.form.submit();"> <!-- calling submit() doesn't invoke onsubmit -->
关于javascript - 在新窗口中提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7099183/