我在elementor自定义代码中有此代码
<script>
jQuery(document).ready(function($){
$('#ship-price').on('click', function(){
var originalPrice = $('#product-price').val();
console.log(originalPrice);
//
var shipPrice = $('#ship-price').val();
console.log(shipPrice);
});
});
</script>
字符串
我试图选择两个元素,我已经使用elementor添加,并在那里我分配了css id.它会发生,我无法读取产品价格和运输价格值.
我需要实现的是显示一个不同的产品价格是使用woocommerce加载,用户点击后.我如何才能解决这个问题?
更新这是产品价格的html
<div class="elementor-element elementor-element-2cf415f elementor-widget elementor-widget-heading" data-id="2cf415f" data-element_type="widget" id="product-price" data-widget_type="heading.default">
<div class="elementor-widget-container">
<h2 class="elementor-heading-title elementor-size-default"><span class="woocommerce-Price-amount amount"><bdi>499,00 <span class="woocommerce-Price-currencySymbol">€</span></bdi></span>*</h2> </div>
</div>
型
这是我需要得到的船价的渲染html
<div id="elementor-tab-content-3201" class="elementor-tab-content elementor-clearfix elementor-active" data-tab="1" role="region" aria-labelledby="elementor-tab-title-3201" style="display: block;"><ul>
<li><a href="#" id="ship-price-a">70€ + IVA</a> ...</li>
<li><a href="#" id="ship-price-b">79€ + IVA</a> ...</li>
</ul></div>
型
1条答案
按热度按时间6tr1vspr1#
a)由于您的ID不简单,因此使用
*
来匹配它们B)此外,您的价格都不在输入元素中,它们在某些HTML元素中,因此使用
.text()
而不是.val()
c)产品价格位于
#product-price
元素的子元素下,因此您也必须修改该代码。工作片段:
个字符