다음과 같은 문제가 있습니다. 2 개의 입력 요소가있는 테이블이 있습니다. 그 중 하나가 다른 것보다 크면, 전체 행은 비교에 따라 색상이 지정되어야합니다. 사이트를로드하는 동안 onchange 이벤트와 처음으로이 작업을 트리거합니다. 절차는 정상적으로 작동하지만 onchange 이벤트는 1/4의 변경 사항 중 하나에서만 트리거됩니다.onChange가 한 번만 트리거합니다.
테이블 문은 다음과 같다 :
<div class="grid">
<table id="table" class="tableRegion w100">
<thead style="text-align:left">
<tr>
<fmt:bundle basename="res/web/ec_resources">
<td class="tableHeader">
...
</td> ...
</fmt:bundle>
</tr>
</thead>
<tbody>
<c:set var="i" value="0"/>
<c:forEach var="participation" items="${someForm.list}">
<tr id="participationRow${i}">
그리고 여기에 테이블의 코드> TR> TD :
$(document).ready(function(){
$('#table > tbody > tr').each(function(i) {
var paid = parseFloat($(this).find('input.paid').val());
var debit = parseFloat($(this).find('input.debit').val());
if (paid == debit)
$('#participationRow'+i).addClass("green");
else if (paid > debit)
$('#participationRow'+i).addClass("yellow");
}
);
});
function isPaid(i){
var paid = parseFloat($('#participationRow'+i).find('input.paid').val());
var debit = parseFloat($('#participationRow'+i).find('input.debit').val());
if (paid == debit)
$('#participationRow'+i).addClass("green");
else if (paid > debit)
$('#participationRow'+i).addClass("yellow");
}
:
<td class="right bottom nowrap">
<div>
<c:out value="${someForm.event.currency.code}"/>
<fmt:formatNumber maxFractionDigits="2" minFractionDigits="2" var="ovFee" value="${overallFee}" />
<c:if test="${someForm.array[i].feeDebit != 0.0}">
<spring:input class="right debit" path="array[${i}].feeDebit" maxlength="7" size="6" onchange="isPaid(${i});" />
</c:if><c:if test="${someForm.array[i].feeDebit == 0.0}">
<spring:input class="right debit" path="array[${i}].feeDebit" maxlength="7" size="6" onchange="isPaid(${i});" value="${ovFee}"/>
</c:if>
</div>
</td>
<td class="right bottom nowrap">
<div class="padT5"><c:out value="${someForm.event.currency.code}"/> <spring:input class="right paid" path="array[${i}].feePaid" maxlength="7" size="6" onchange="isPaid(${i});"/></div>
</td>
호출되는 가량이 스크립트는 다음과 같다
이벤트가 한 번만 트리거되는 이유는 무엇입니까? 나는 jQuery와 onclick을 교차 점검했다. 그들은 모두 한 번만 트리거됩니다. 아무리 멀리 클릭하거나 탭하여 떠날지라도 상관 없습니다.
당신은 [change] (http://api.jquery.com/change/) – Vijaychandar
이라는 이벤트를 시도 했습니까? "내가 jQuery와 교차 확인했습니다." $ ('input [type = text]')를 시도했습니다. change (function() {...}); 더 이상 성공하지 못했습니다 ... – DonMarco
i 값을 전달하는 데 문제가있을 수 있습니다. isPaid 함수의 경고 상자로 확인하십시오. – Vijaychandar