[英]Make jQuery click on a button when someone has confirmed (dialog box)
我有一个 wordpress 拍卖网站,当有人点击“出价”按钮时,我想添加一个带有 jquery 的确认对话框。 我可以使用默认的系统对话框来实现这一点,但我想要一个带有 jQuery 的自定义对话框。 一旦最终用户确认出价,我如何让它点击出价按钮?
下面是代码示例:
<button type="submit" class="bid_button button alt"><?php echo wp_kses_post( apply_filters( 'bid_text', esc_html__( 'Bid', 'auctions-for-woocommerce' ), $product ) ); ?></button>
<script>
jQuery('button').confirm({
title: 'titletext',
content: 'content text"',
type: 'red',
buttons: {
ok: {
text: "OK",
btnClass: 'btn-primary',
keys: ['enter'],
action: function(){
console.log('Brukeren bekreftet "OK"');
}
},
No: function(){
text: "No",
jQuery.alert('Kansellert!');
console.log('the user clicked cancel');
}
}
});
</script>
似乎这个库不是为通过按钮提交表单而创建的,更像是将它用于<a>
标签,源 - https://github.com/craftpip/jquery-confirm/issues/229
我想我会给你一个方法来解决你的问题。 现在我正在阻止按钮未确认时的默认行为,并在确认时再次触发它,但这次按钮可以提交表单。 submitButton
id submitButton
添加到您的按钮以使其个性化。
<button type="submit" id="submitButton" class="bid_button button alt"></button>
<script>
var confirmed = false;
$('#submitButton').on('click', function() {
if (!confirmed) {
event.preventDefault();
$.confirm({
title: 'titletext ',
content: 'content text"',
type: 'red',
buttons: {
ok: {
text: "OK",
btnClass: 'btn-primary',
keys: ['enter'],
action: function() {
confirmed = true;
$('#submitButton').click()
console.log('Brukeren bekreftet "OK"');
}
},
No: function() {
text: "No",
jQuery.alert('Kansellert!');
console.log('the user clicked cancel');
}
}
})
} else {
confirmed = false
}
})
</script>
希望我能帮助你。 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.