각 값 필드는 예를 들어? 수량 필드의 ID에서 파생 될 수있는 ID 속성? 그렇다면 매우 빠르고 고통 스럽습니다. 주어진 :
<table id="basket">
<tr class="basket-row">
<td class="basket-quantity">
<input type="text" id="product1234_quantity">
</td>
<td class="basket-subtotal">
<input type="hidden" id="product1234_unitprice" value="20">
<input type="text" readonly="readonly" id="product1234_subtotal">
</td>
</tr>
<tr class="basket-row">
<td class="basket-quantity">
<input type="text" id="product5678_quantity">
</td>
<td class="basket-subtotal">
<input type="hidden" id="product5678_unitprice" value="30">
<input type="text" readonly="readonly" id="product5678_subtotal">
</td>
</tr>
</table>
각 제품의 단가는 숨겨진 속성이지만 여기에 장바구니가 저장되는 위치는 나와 있습니다. 어딘가에서 얻을 수 있다고 가정하고 jQuery를 가정 해 봅시다. 다른 아이디에서 ID를 추출 할 수없는 경우
$('#basket').on('change','.basket-quantity input',function(e) {
$('#'+this.id.replace('_quantity','_subtotal')).val(Number($('#'this.id.replace('_quantity','_unitprice')))*Number(this.value));
});
, 당신은 좀 더 복잡한 DOM의 질의를해야 할 것입니다,하지만 포인트는 핸들러의 런타임에, 당신은 어떤 입력을 '파악해야 다시 업데이트.
사용중인 프레임 워크 (있는 경우)를 지정하지 않았습니다. 평범한 JS에서는이 기능을 통해 브라우저 간 호환이 가능하고 이벤트 첨부 및 처리를 표준화 할 수있는 많은 추가 코드가 필요합니다. 각각의
은 당신이 지금까지 가지고 않습니다은 diff TR에서 동일한 TD를받을 수 있나요? – bernie