0
我有WooCommerce生成的代碼如下位顯示可用的送貨選項:如果選中某個單選按鈕,如何禁用剩餘的單選按鈕?
<ul id="shipping_method">
<li>
<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_flat_rate5" value="flat_rate:5" class="shipping_method" checked='checked' />
<label for="shipping_method_0_flat_rate5">Call 386-410-4757 for Shipping Quote</label> </li>
<li>
<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_wf_shipping_uspsd_express_mail" value="wf_shipping_usps:D_EXPRESS_MAIL" class="shipping_method" />
<label for="shipping_method_0_wf_shipping_uspsd_express_mail">Priority Mail Express™ (USPS): <span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">$</span>22.95</span></label> </li>
<li>
<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_wf_shipping_uspsd_priority_mail" value="wf_shipping_usps:D_PRIORITY_MAIL" class="shipping_method" />
<label for="shipping_method_0_wf_shipping_uspsd_priority_mail">Priority Mail® (USPS): <span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">$</span>6.45</span></label>
</li>
</ul>
我需要能夠做的是禁用單選按鈕2和3,如果選擇了第一個單選按鈕。
我曾經嘗試這樣做無濟於事:
$('.shipping_method').click(function(){
if(this.value == 'flat_rate:5' && this.checked){
console.log($('input[value=wf_shipping_usps:D_EXPRESS_MAIL], input[value=wf_shipping_usps:D_PRIORITY_MAIL]'));
$('input[value=wf_shipping_usps:D_EXPRESS_MAIL], input[value=wf_shipping_usps:D_PRIORITY_MAIL]').prop('disabled', true);
}
else{
$('.shipping_method').not(this).prop('checked', false).prop('disabled', false);
}
});
任何幫助,將不勝感激!
感謝,
辛西婭通過AJAX,這意味着
由於只能從指定的組中選擇1個單選按鈕,因此禁用其他組件似乎有點多餘 - 並且會讓用戶煩惱,因爲如果他們誤點擊,他們將無法更改選擇。 –
它需要完成。我在Woocommerce有一些產品,因爲運輸不能在線計算,所以他們需要打電話發貨。僅限於那些產品,Call for Shipping顯示爲運費選項。 – Cynthia