0
使用php foreach得到如下的html。因此id
就像价格1,价格2,价格3等。jquery如何获得id的id值(最近的id/id在同一行中)
用户可更改数量。在这种情况下,我必须将价格乘以更改的数量。我决定用jQuery来做。
首先访问quantity
。
$('[id^="quantity"]').change(function(){
var quantity = $(this).val();
});
但无法获得价格的html值。试图
var price = $(this).find('[id^="price"]').attr('id');
var price = $(this).find('div[id^="price"]').html();
在这两种情况下,得到了undefined
这里是HTML代码的一部分
<div class="shop_cart_box_around">
<div class="shop_cart_price">
<div class="span_cart_name_txt" id="price1">789</div>
</div>
<div class="shop_cart_quantity">
<input type="text" name="quantity[]" id="quantity1" value="3"/>
</div>
</div>
<div class="shop_cart_box_around">
<div class="shop_cart_price">
<div class="span_cart_name_txt" id="price2">54</div>
</div>
<div class="shop_cart_quantity">
<input type="text" name="quantity[]" id="quantity2" value="1"/>
</div>
</div>
这应该得到的价格div的ID,但它不会得到的价格。 – j08691 2014-11-01 18:23:14
var price = $(this).closest(“。shop_cart_box_around”)。find('[id^=“price”]').html();这工作。谢谢! – user2118559 2014-11-01 18:25:06
使用'val()'而不是'html()'输入元素 – 2014-11-01 18:26:44