如何我可以禁用button.single_add_to_cart_button在其他股利,如果我有價格span.amount 0,00€?隱藏按鈕,如果價格是0,00€
看看下面的代碼:
<form class="cart" enctype="multipart/form-data" method="post" novalidate="novalidate">
<div id="tm-extra-product-options" class="tm-extra-product-options tm-custom-prices tm-product-id-7045 tm-cart-main" data-product-id="7045" data-cart-id="main">
<div class="tm-totals-form-main" data-product-id="7045">
<input class="cpf-product-price" type="hidden" name="cpf_product_price" value="0">
<div id="tm-epo-totals" class="tm-epo-totals tm-custom-prices-total tm-cart-main" data-variations="[]" data-variations-subscription-period="[]" data-subscription-period="" data-variations-subscription-sign-up-fee="[]" data-subscription-sign-up-fee="0" data-prices-include-tax="" data-tax-display-mode="excl" data-tax-string="" data-tax-rate="22" data-taxable="1" data-force-quantity="0" data-tm-epo-dpd-suffix="" data-tm-epo-dpd-prefix="" data-fields-price-rules="0" data-product-price-rules="[]" data-price="0" data-type="simple" data-is-sold-individually="" data-is-subscription="" data-cart-id="main" data-theme-name="">
<dl class="tm-extra-product-options-totals tm-custom-price-totals">
<dt class="tm-options-totals">Options amount</dt>
<dd class="tm-options-totals">
<dt class="tm-final-totals">Prezzo Totale:</dt>
<dd class="tm-final-totals">
<span class="amount final">0,00€</span>
</dd>
</dl>
</div>
</div>
<div class="iva_esc">
<div class="quantity">
<input type="hidden" value="7045" name="add-to-cart">
<button class="single_add_to_cart_button button alt" type="submit" style="display: block;">Vai al pagamento</button>
其他用戶,都sended給我這個代碼:
<script>
$(function() {
//check if all items are zero
var disable = $(".cart span.amount.final").toArray().every(function(item) {
return $(item).text() === "0,00€";
});
//disable button if necessary
$(".cart button.single_add_to_cart_button").prop("disabled", disable);
});
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
此代碼工作完美,但現在的價格,當我需要主動爲0不同, 00€
凡你需要隱藏它,客戶端或服務器端,從而它根本不會出現在輸出中?你應該相應地調整你的標籤。 – jeroen
所以閱讀跨度的文本,如果它是0,比隱藏按鈕...你在掙扎什麼? – epascarello
if($(「。amount」)。html()===「0,00€」){$(「。your-button」)。attr(「disabled」,true);} 但是最佳實踐 - 在服務器端禁用按鈕 – esperant