我想获得第二个 div(总价),而不是第一个 div。
此外,我想在div中添加一个$符号,但是当它试图将数据转换为Int时,显然“$”会导致错误。 我有一个变通方法,但是有没有办法连接 $?
非常感谢。
<!-- Product #1 -->
<div class="item">
<div class="quantity">
<button class="plus-btn" type="button" name="button">
</button>
<div class="total-price">22</div> <!--I dont want this one -->
</div>
<div class="total-price">22</div> <!--I want to access this div -->
</div>
JQuery
$('.plus-btn').on('click', function(e) {
e.preventDefault();
//Increase cost
var $this = $(this);
var $cost = $this.closest('div').find('div');
var costValue = parseInt($cost.html());
costValue += costValue;
$cost.html(costValue);
});
最佳答案
$('.plus-btn').on('click', function(e) {
e.preventDefault();
var $this = $(this);
var $cost = $this.closest('.quantity').siblings('.total-price');
var costValue = parseInt($cost.html());
costValue += costValue;
$cost.html(costValue);
});
关于javascript - 获取此 <div> 之外的 <div>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58195107/