这是我的代码:
var woocommerce_price_displayed = $('.product_intial_price').find('.woocommerce-Price-amount').text();
$(".yearly-package").click(function () {
var yearprice = $('#year_price').text();
$('.electro-price').find('.woocommerce-Price-amount').text(function () {
return $(this).text().replace(woocommerce_price_displayed, yearprice);
});
})
$(".halfyear-package").click(function () {
var halfyearprice = $('#halfyear_price').text();
$('.electro-price').find('.woocommerce-Price-amount').text(function () {
return $(this).text().replace(woocommerce_price_displayed, halfyearprice);
});
})
$(".single-package").click(function () {
var oneprice = $('#one_price').text();
$('.electro-price').find('.woocommerce-Price-amount').text(function () {
return $(this).text().replace(woocommerce_price_displayed, oneprice);
});
})
单击div时,价格将改变。但是,如果我再次单击其他按钮-价格将不会再次更改。
怎么了?为什么只能在首次点击时使用?
这基本上是每个包装的html:
<div class="ps-package single-package first-pack" data-val="1">
<div class="ps-name">Single Package</div>
<div id="one_price" class="ps-price">$99</div>
</div>
<span class="electro-price"><ins><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">$</span>99.00</span></ins> <del><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">$</span>150.00</span></del></span>
当我为每个这样的函数添加var woocommerce_price_displayed = oneprice;
时:
$(".halfyear-package").click(function () {
var halfyearprice = $('#halfyear_price').text();
$('.electro-price').find('.woocommerce-Price-amount').text(function () {
return $(this).text().replace(woocommerce_price_displayed, halfyearprice);
woocommerce_price_displayed = halfyearprice;
});
它根本无法工作,甚至一次也不会!为什么?