[英]Onsubmit doesn't work in Chrome
我有两种形式和一个按钮。 在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>
除非您有充分的理由使用仅使用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>
为什么不将两个提交都绑定到您的a?
onclick="$('#send_mail').submit(); $('#registerForm').submit();"
如果您希望其他表单在第一个表单之后提交:
onclick="$('#send_mail').submit( function() {$('#registerForm').submit();}); "
假设你在这里使用jQuery
据我了解,您想使用链接提交表格吗?
为什么不使用“普通” javascript呢? 没有jQuery: document.getElementById(....).submit()
或以常规jQuery方式将Submit事件链接到链接:
$(document).ready(function() {
$(".yourLinkClass").click(function() { // or "#yourLinkId" for that matter
$("#registerForm").submit();
});
});
您还可以使用提交按钮;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.