여기에 첫 번째 질문과 초보 프로그래머, 간단하고 요점을 유지하려고 노력할 것입니다.
내 HTML 코드에는 수백 개의 행으로 구성된 테이블이 있고 각 행 옆에 확인란이 있으므로 사용자가 원하는 행을 '선택'할 수 있습니다. 사용자가 300 행과 400 행 (임의의 숫자)을 선택하면 300-400 행이 모두 검사됩니다. 이 작업을 수행하는 방법을 전혀 모르겠습니다. 동료들은 가능하다고 말합니다. 어떤 도움을 주시면 대단히 감사하겠습니다. 감사합니다.
var checkbox = $("#wrap input[type='checkbox']");
checkbox.click(function() {
var first = $("#wrap input[type='checkbox']:checked").first().parent().index(),
last = $("#wrap input[type='checkbox']:checked").last().parent().index(),
length = checkbox.length;
for (var i = 0; i < length; i++) {
if (i >= first && i <= last)
checkbox[i].checked = true;
else
checkbox[i].checked = false;
}
});
span {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="wrap">
<span>Row <input type="checkbox" name='test'></span>
<span>Row <input type="checkbox" name='test'></span>
<span>Row <input type="checkbox" name='test'></span>
<span>Row <input type="checkbox" name='test'></span>
<span>Row <input type="checkbox" name='test'></span>
<span>Row <input type="checkbox" name='test'></span>
<span>Row <input type="checkbox" name='test'></span>
<span>Row <input type="checkbox" name='test'></span>
<span>Row <input type="checkbox" name='test'></span>
<span>Row <input type="checkbox" name='test'></span>
<span>Row <input type="checkbox" name='test'></span>
<span>Row <input type="checkbox" name='test'></span>
<span>Row <input type="checkbox" name='test'></span>
<span>Row <input type="checkbox" name='test'></span>
<span>Row <input type="checkbox" name='test'></span>
<span>Row <input type="checkbox" name='test'></span>
<span>Row <input type="checkbox" name='test'></span>
</div>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다