세 개의 div가 있습니다. 수량, 가격 및 비용. 비용은 가격 * 수량의 곱셈입니다.한 div의 텍스트가 다른 두 div의 텍스트를 기반으로 동적으로 변경됩니다.
<div class="qty">1</div>
<div class="price">49</div>
<div class="cost"><div>
<div class="add">ADD</div>
다음으로 qty 값을 증가시키는 추가 버튼이 있습니다. jQuery를
$('.add').on('click',function(){
$('.qty').text(parseInt($('.qty').text()) + 1);
});
는 지금은 수량 * 가격입니다 "비용"DIV에서 텍스트를 넣어합니다. 그리고 이것은 수량의 변화에 따라 동적으로 변해야합니다. 어떻게해야합니까 ?? 다음은 remove
버튼을 추가하려는 경우
$('.add').on('click',function(){
var qty = parseInt($('.qty').text()) + 1,
price = parseInt($('.price').text());
$('.qty').text(qty);
$('.cost').text(qty * price);
});
:
이미 수행중인 작업과 매우 유사합니다. 시도 했니? 아마도 당신은 그 코드가 어떻게 실패하는지 함께 게시 할 수 있습니다. –
그리고 [radix with'parseInt()'] (https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/parseInt)를 사용하십시오. –