[英]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.