2
근무 만약 내가 jQuery 코드jQuery를 각()와 문은 첫 번째 요소
$(document).ready(function() {
$('#line_items_table tr').each(function() {
var self = $(this);
console.log(parseInt(self.attr('data-id')));
if (!$.inArray(parseInt(self.attr('data-id')), errors)) {
console.log("inside conditional");
self.addClass('incorrect_item');
}
});
});
errors = [19,20,21]
와의 간단한 조각이, 내가이 출력
3417
3419
"inside conditional"
3420
3421
3422
3423
3424
3425
그리고 errors = [20,21]
,이 출력을 얻을 :
3417
3419
3420
"inside conditional"
3421
3422
3423
3424
3425
왜 첫 번째 요소에서만 작동합니까 ??
+1 바로 게시하려고했습니다. – VisioN
당신이 왜 -1을 검사하는지 설명해 주시겠습니까? –
* $ .inArray() 메소드는 일치하는 것이 없을 때 -1을 반환한다는 점에서 JavaScript의 native .indexOf() 메소드와 유사합니다. * - http : // api .jquery.com/jQuery.inArray / – CodingIntrigue