我想在選擇另一個無線電時選擇/檢查單選按鈕。我正在使用.prop('checked', true);,但它不起作用。
這就是我所擁有的:
add_action( 'woocommerce_after_add_to_cart_form', 'conditionally_hide_show_new_field', 9999 );
function conditionally_hide_show_new_field() {
wc_enqueue_js( "
$('input[type=radio][name=testradio]').change(function() {
if (this.value == 'my_value') {
$('#testradio').prop('checked', true);
}
});
");
}
uj5u.com熱心網友回復:
change您的事件是否在單選按鈕更改時觸發?由于您的代碼取決于加載的 jQuery 和 DOM,因此請嘗試將代碼包裝起來,$(function() {}以便jQuery在加載后執行:
add_action( 'woocommerce_after_add_to_cart_form', 'conditionally_hide_show_new_field', 9999 );
function conditionally_hide_show_new_field() {
wc_enqueue_js( "
$(function() {
$('input[type=radio][name=testradio]').change(function() {
if ($(this).val() == 'my_value') {
$('#testradio').prop('checked', true);
}
});
});
");
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/439732.html
上一篇:如何將圓圈連續放置在隨機位置?
