나는이 JQuery와jQuery 중복 요소를 여러 개 만드는 방법은 무엇입니까?
$('#qty input').on('input', function() {
var price = $(this).prev('#price input').val();
var qty = $(this).val();
$('#amount').html(parseFloat(price * qty).toFixed(2));
$('#linetotal input').val(parseFloat(price * qty).toFixed(2));
});
의 라인과 HTML을
<tr>
<td><select name='itemone[]'>
<?php echo $items; ?>
</select></td>
<td><input name='itemtwo[]' type="text" class="irow"></td>
<td id="price"><input name='itemthree[]' type="number" step="any" class="irow" value="0.00"></td>
<td id="qty"><input name='itemfour[]' type="number" step="any" class="irow" value="1"></td>
<td id="linetotal" class="text-right"><p id="amount">0.00</p>
<input name='itemfive[]' type="hidden" class="irow" value="0" >
</td>
</tr>
는 지난 TD에 표시됩니다 세 번째 TD와 네 번째 TD과 결과의 값을 계산하는 데 무엇을 . 성공했습니다. 그러나 정확한 테이블을 새로운 테이블 데이터로 복사 할 버튼을 클릭하면 동일한 "ID"가 사용됩니다. 지금, 그 행의 계산이 작동하지 않습니다.
두 개 이상의 동일한 ID가 있어도 같은 ID를 사용하여 계산할 수있는 방법입니까?
나는 sibling()
, next()
, prev()
을 시도했지만 사용하지 못했습니다.
나를 도울 수있는 방법.
TIA, 니미츠
편집 :
이여기에 성공적인 이미지와 : https://docs.google.com/file/d/0B6f93ZQiD1h_V0dvbThocVdlekU/edit?usp=drivesdk
두 개 이상의 TR (실패) 경우 : https://docs.google.com/file/d/0B6f93ZQiD1h_MmxzYUVLT3JzQWs/edit?usp=drivesdk
Hello @angusf, 코드에 대한 것보다. 잘 작동하지만 편집하는 동안 변경하고 싶었습니다. '$ (". qty : input"). on'으로 변경하려고했지만 작동하지 않습니다. 그걸 도와 줄 수있어? –
@ NimitzEBatiocoJr. .change() 이벤트는이 작업을 수행합니다. 텍스트 상자에 숫자를 입력하는 경우 탭을 클릭하거나 다른 곳을 클릭하여 이벤트를 트리거하거나 .price 입력에 0.0 이외의 값이 있는지 확인하십시오. – angusf
예, 변경되었지만 텍스트 상자의 숫자를 변경하는 동안 출력 값이 변경되면 더 좋을 것입니다. 그래도 코드에 감사드립니다. –