[英]JQuery - onclick and .click handlers on element with same ID
how can I solve this? 我该如何解决? At the end of order proces on confirmation page I have form of payment method (could be various, the button id is the same) After click on confirm order button I need to call some_script.php using jquery and simultaneously redirect to payment gateway.
在确认页面上的订单处理结束时,我有一种付款方式(可以是多种形式,按钮ID相同)。单击确认订单按钮后,我需要使用jquery调用some_script.php并同时重定向到支付网关。 After click on confirm button only onclick="$('#payment').submit(); is handled, page is redirected but some_script.php is not called. Thanks for help.
单击确认按钮后,仅处理onclick =“ $('#payment')。submit();;页面被重定向,但未调用some_script.php。感谢您的帮助。
<div class="payment">
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="payment">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
....
</form>
<div class="buttons">
<div class="right">
<a id="button-confirm" class="button" onclick="$('#payment').submit();">
<span>Confirm</span></a>
</div>
</div>
</div>
<script>
$('#button-confirm').click(function() {
$.get(
'some_script.php',
{order_id: '<?php echo $order_id; ?>'},
'html'
);
});
</script>
this maybe helful 这也许很开心
<script>
$('#button-confirm').click(function (e) {
e.preventDefault();
$.get(
'some_script.php',
{order_id: '<?php echo $order_id; ?>'},
'html'
);
$('#payment').submit();
});
</script>
is this what you looking for? 这是你要找的吗?
edit : 编辑:
replace submit section on script with this, i think it's worked 用这个替换脚本上的提交部分,我认为这是有效的
var submitForm = $('#payment');
if(submitForm){
$('#payment').submit();
}
edit2: EDIT2:
if there is various id for form tag, better use parent class and form selector to select the form 如果表单标签有各种ID,则最好使用父类和表单选择器来选择表单
var submitForm = $('.payment form');
if(submitForm){
$('.payment form').submit();
}
This is because you have written 2 different events for the same action. 这是因为您为同一操作编写了2个不同的事件。 onclick="$('#payment').submit(); is handled because its written an inline.
onclick =“ $('#payment')。submit();之所以会被处理,是因为其已编写为内联。
For getting your expected result you mus change the code as below. 为了获得预期的结果,您必须更改以下代码。
<a id="button-confirm" class="button">
and 和
<script>
$('#button-confirm').click(function() {
$.get(
'some_script.php',
{order_id: '<?php echo $order_id; ?>'},
'html'
);
$('#payment').submit();
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.