1

我有两个表格和一个按钮。在 Firefox 中一切正常。我得到一个新窗口,使用 Paypal 付款,在发生所有事情的窗口中,我提交了 send_mail 表单,该表单将向用户发送电子邮件。如何在 Chrome 中进行这项工作?为什么它不起作用?我已经尝试过任何东西(或者我认为)!

所以:

<form name="registerForm" id="registerForm" target="_blank" action="paypal_url" method="post" onsubmit="$('#send_mail').submit();">
...
</form>

<form name="send_mail" id="send_mail" action="" method="post">
...
</form>

<a onclick="$('#registerForm').submit()">Go to paypal and send confirmation mail</a>
4

3 回答 3

4

除非您有充分的理由使用仅 javascript 提交,否则为什么在出现 javascript 错误时将表单设置为不可用?

使用 submit 类型的标准表单输入,给它一个 id,根据需要通过 javascript 更改提交的外观或文本,并在该功能之上创建 onclick 和 onsubmit 事件并让它们返回 false。更好的后备方案。

我不确定你为什么要尝试一次提交两个表单,但是这个替代方案怎么样(请注意,我没有测试过这段代码,但它应该传达这个想法):

<script type='text/javascript'>
$('#fallback-register-submit').hide(); // Hide the submit button.
$('#registration-link').show().click(function (){ // Show the link and attach the action.
    $('#registerForm').submit();
    return false; // Don't bother following the link anchor.
});
</script>

<form name="registerForm" id="registerForm" target="_blank" action="paypal_url" method="post""><!-- Single form that does all of the submitting. -->
...
...
<input type='submit' id='fallback-register-submit'>Register</input><!-- In the event of a javascript error for their browser, they can still buy your stuff! -->
<a id='registration-submit' style='display:none'>Go to paypal and send confirmation mail</a>
</form>
于 2011-02-23T16:22:25.087 回答
2

为什么不将两个提交都绑定到您的a?

onclick="$('#send_mail').submit(); $('#registerForm').submit();"

如果您希望在第一个表单之后提交另一个表单:

onclick="$('#send_mail').submit( function() {$('#registerForm').submit();}); "

假设你在这里使用 jquery

于 2011-02-23T16:14:46.880 回答
1

据我了解,您想使用链接提交表单吗?

那么为什么不使用“普通”javascript呢?没有 jQuery:document.getElementById(....).submit()

或者以普通的 jQuery 方式将提交事件链接到链接:

$(document).ready(function() {
 $(".yourLinkClass").click(function() { // or "#yourLinkId" for that matter
  $("#registerForm").submit();
 });
});

你也可以使用提交按钮;)

于 2011-02-23T16:20:41.847 回答