Onsubmit在Chrome中不起作用
我有两种形式和一个按钮。一切工作正常在Firefox。我得到一个新的窗口,一个Paypal付款,并在窗口中发生的一切,我得到的send_mail表单提交,将发送电子邮件给用户。我如何在Chrome中完成这项工作?为什么它不起作用?我已经尝试过任何东西(或者我认为)!Onsubmit在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>
除非你有一个很好的理由使用仅限javascript的提交,为什么将表单设置为不可用,如果有javascript错误?
使用类型为submit的标准表单输入,给它一个id,根据需要通过javascript更改提交的外观或文本,然后创建onclick onslick作为该功能顶层的事件,并让它们返回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>
,因为一种形式是贝宝形式,另一种是谢谢+更新数据库上的东西 – Bogdan 2011-02-23 18:26:41
嗯,如果你不能合并表格,当然你可以添加额外的提交到我发布的代码,尽管这并不理想。我唯一能想到的另一种方法是在PayPal之前提交表单,以便您了解用户正在经历您的流程,然后让PayPal表单成为多步骤中的最后一步形成。如果这对你来说不值得麻烦,或者如果它不是一个非常重要的付款表单,那么为JavaScript用户留下一个表单或其他未提交的表单可能实际上只剩下所有这些。 – Kzqai 2011-02-24 00:05:36
是的,这就是我要做的。我没有看到任何其他的方式...... – Bogdan 2011-02-24 07:34:22
为什么不绑定都提交给你一个?
onclick="$('#send_mail').submit(); $('#registerForm').submit();"
,如果你想在其他形式提交后的第一个:
onclick="$('#send_mail').submit(function() {$('#registerForm').submit();}); "
假设你使用jQuery这里
第一种方法只提交#registerForm(打开PayPal窗口,但不提交#send_mail),其次没有任何内容.. – Bogdan 2011-02-23 17:39:18
据我了解,你要提交表单使用链接?
为什么不使用“普通”JavaScript呢?没有jQuery的:document.getElementById(....).submit()
或链接提交事件在正常jQuery的方式链接:
$(document).ready(function() {
$(".yourLinkClass").click(function() { // or "#yourLinkId" for that matter
$("#registerForm").submit();
});
});
而且你还可以使用提交按钮;)
使用'submit()'时''onsubmit'不会被触发。 – pimvdb 2011-02-23 16:15:34