HTML に次の div コレクションがあります。ユーザーの操作に応じて動的にレプリケートするように設計されています。
<div class="bill-item">
<!-- Section for a single item -->
<div class="bill-item-img">
<!-- Section for Item pic -->
</div>
<div class="bill-item-description">
<!-- Section for Item description and pricing -->
<div class="bill-item-name">
<p class="bill-item-name-left">Normal Cofee</p><p class="bill-item-name-right">170.00</p>
<div class="clear"></div>
</div>
<div class="bill-item-price">
<span>170.00 USD</span>
</div>
<div class="bill-item-amount">
<span>2</span>
</div>
</div>
<div class="bill-amount-selection">
<!-- Section where the increment & decrement of item amount goes -->
<a class="amount-increase" href="#"></a>
<a class="amount-decrease" href="#"></a>
</div>
</div>
これは、要素の HTML レンダリング イメージです。
請求項目金額のスパン値を増やすために、次のスクリプトを作成しました。
$(".amount-increase").click(function(){
x+=1;
$(".bill-item-amount span").html(x);
});
$(".amount-decrease").click(function(){
if(!x<=0){
x-=1;
$(".bill-item-amount span").html(x);
}
});
これはうまく機能しますが、両方のスパン要素の値を更新します。私が望むのは、クリックされた要素のイベントをキャッチし(今はそうしています)、それぞれのスパンのスパン値を増やすことです。javascript を使用して更新するスパンを除外するにはどうすればよいですか?