Onsubmit在Chrome中不起作用 [英] Onsubmit doesn't work in Chrome
问题描述
我有两种形式和一个按钮.在Firefox中一切正常.我得到一个带有Paypal付款的新窗口,在发生所有事情的窗口中,我提交了send_mail表单,该表单将向用户发送电子邮件.如何在Chrome浏览器中执行此操作?为什么不起作用?我已经尝试过任何事情(或者我想)!
I have two forms and a button. Everything works fine in Firefox. I get a new window, with a Paypal payment, and in the window where everything happened i get the send_mail form submitted that will send an e-mail to the user. How can I make this work in Chrome? Why it's not working? I've tried anything (or so I think)!
所以:
<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错误,为什么将表单设置为不可用?
Unless you have a really good reason to use a javascript-only submit, why set up the form to be unusable if there is a javascript error?
使用类型为Submit的标准表单输入,为其提供一个ID,根据需要通过javascript更改提交的外观或文本,并创建onclick& onsubmit事件是该功能之上的一层,并使它们返回false.更好的后备.
Use a standard form input of type submit, give it an id, alter the look or text of the submit via javascript as necessary, and create onclick & onsubmit events as a layer on top of that functionality and have them return false. Better fallbacks.
我不确定您为什么尝试一次提交两个表单,但是这种选择怎么样(请注意,我尚未测试此代码,但它应该传达了这个想法):
I'm not sure why you're trying to submit two forms at once, but how about this alternative (note that I haven't tested this code, but it should convey the idea):
<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>
这篇关于Onsubmit在Chrome中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!