두 개의 테이블 행에는 각각 <td>
에있는 3 개의 확인란이 있습니다.여러 테이블 행의 여러 확인란에서 값 가져 오기
체크 박스가 선택된 특정 규칙에 따라 해당 행에 네 번째 <td>
을 표시하려고합니다. 각 행은 다음과 같이이다 :
HTML
<tr class="tableRow">
<td>
<input class="select" class="select" type="checkbox" value="select"/>
</td>
<td>
<input class="voice" class="voice" type="checkbox" value="voice">
</td>
<td>
<input class="mail" class="mail" type="checkbox" value="mail"/>
</td>
<!--The <td>'s i want the results of the checkboxes to show -->
<td class="initial-cost">Initial cost</td>
<td class="voicemail-and-initial-cost">VoiceMail and Initial Cost</td>
<td class="email-and-initial-cost">Email and Initial Cost</td>
<td class="all-services-cost">All Services Cost</td>
</tr>
내가 좀 일이 jQuery를 가지고 있지만 모든 테이블 행을 '이다'... 비용 '의 오히려 각 행보다 개별적으로 jQuery를
$(document).ready(function() { //on page load....
$(".voicemail-and-initial-cost").hide(); //hide all cost elements
$(".email-and-initial-cost").hide(); //hide all cost elements
$(".all-services-cost").hide(); //hide all cost elements
$(".select").change(function(event) { //when #select is clicked...
if ($(this).is(":checked")) { //if this checkbox has been checked...
$(".initial-cost").show(); //show .initial-cost element
} else { //otherwise...
$(".voicemail-and-initial-cost").hide(); //hide all cost elements
$(".email-and-initial-cost").hide(); //hide all cost elements
$(".all-services-cost").hide(); //hide all cost elements
}
});
$(".voice").change(function(event) { //when #voice is clicked...
if ($(this).is(":checked")) { //if this checkbox has been checked...
if ($('.mail').is(":checked")) { //check to see if #mail is checked too and if it is...
$(".initial-cost").hide(); //hide .initial-cost
$(".voicemail-and-initial-cost").hide(); //hide .voicemail-and-initial-cost
$(".email-and-initial-cost").hide();
$(".all-services-cost").show(); //show .all-services-cost
} else { //but if #mail is not checked....
$(".initial-cost").hide(); //hide .initial-cost
$(".voicemail-and-initial-cost").show(); //show .voicemail-and-initial-cost instead
}
} else { //otherwise if this checkbox is not checked...
if(($('.select').is(":checked")) && ($('#mail').is(":checked"))){ //and .select AND .mail is checked however...
$(".initial-cost").hide(); //hide .initial-cost
$(".all-services-cost").hide(); // hide .all-services-cost
$(".email-and-initial-cost").show(); //show .email-and-initial-cost instead
} else if (($('.select').is(":checked")) && (!$('.mail').is(":checked"))){ //otherwise if #select is checked AND #mail is NOT checked....
$(".voicemail-and-initial-cost").hide();
$(".initial-cost").show();
}
}
});
$(".mail").change(function(event) { //when #mail is clicked...
if ($(this).is(":checked")) { //if this checkbox has been checked...
if ($('.voice').is(":checked")) { //check to see if #voice is checked too and if it is...
$(".initial-cost").hide(); //hide .initial-cost
$(".voicemail-and-initial-cost").hide(); //hide .voicemail-and-initial-cost
$(".email-and-initial-cost").hide(); //hide .email-and-initial-cost
$(".all-services-cost").show(); //show .all-services-cost
} else { //but if #voice is not checked....
$(".initial-cost").hide(); //hide .initial-cost
$(".email-and-initial-cost").show(); //show .email-and-initial-cost instead
}
} else { //otherwise if this checkbox is not checked...
if(($('.select').is(":checked")) && ($('.voice').is(":checked"))){ //and #select and #voice is checked however...
$(".all-services-cost").hide(); // hide .all-services-cost
$(".voicemail-and-initial-cost").show(); //show .voicemail-and-initial-cost
} else if (($('.select').is(":checked")) && (!$('.voice').is(":checked"))){ //if this checkbox is not checked AND #voice is NOT checked...
$(".all-services-cost").hide(); // hide .all-services-cost
$(".voicemail-and-initial-cost").hide();
$(".email-and-initial-cost").hide();
$(".initial-cost").show(); //show .initial-cost instead
}
}
});
}); //end of ready
은 지금은 단지 요소를 대상으로 생각
$(".initial-cost").hide();
같은으로 : -에서조차 오류 메시지를
$('td').next(':has(.initial-cost):first').hide();
하지만 지금은 모든 일이 아무것도 얻을 여기에 무슨 문제 행, 나는에서 JQuery와 선택기를 변경해야 콘솔.
규칙 자체가 문제가 아니라 사실 그 규칙이 표 행당 적용되는 것이지 모든 항목을 한꺼번에 적용하지 않기를 바랍니다. 나는 이것이 의미가 있고 누군가가 저를 올바른 방향으로 향하게하기를 바랍니다. 여기 나는 그것이 도움이 될 것입니다 무슨의 JSfiddle입니다 :이 같은 https://jsfiddle.net/monkeyroboninja/5n0v0eL5/
ID는 문서에 고유해야합니다. 해당 테이블 행이 실제로 반복되는 경우 유효하지 않은 HTML이 있으며 실행중인 코드가 작동하지 않습니다. 대신 클래스 및 이벤트 위임을 사용하십시오. –
아하, ID에 대해 지금 수정 중입니다. – Liam