我从Jakecigar那里得到了这个问题的解决方案
link
Ids have to be unique. Donât use them for your "form"s.
https://jsfiddle.net/jakecigar/1mt7ojL0/41/ <--
<form data-for="1"> â¦
jquery:查询:
// JavaScript Document
$(document).ready(function() {
$('.selector').each(function() {
$(this).on('click', check);
});
$('.all').each(function() {
$(this).on('click', all);
});
function all(event) {
if ($(this).is(':checked')) {
$("input:checkbox:not(:checked)", $(this).parents('form')).not(this).prop("checked", true);
} else {
$("input:checkbox(:checked)", $(this).parents('form')).not(this).prop("checked", false);
}
//$('.selector').prop("checked", this.name === "SelectAll");
check(event);
}
function check(event) {
var checked = $(".selector:checked").map(function() {
return this.name
}).get()
$('td').removeClass("highlight").filter(function() {
return $.inArray($(this).text(), checked) >= 0 &&
$('[data-for="' + ($(this).index() + 1) + '"]').find('[name="' + $(this).text() + '"]').is(":checked")
}).addClass("highlight")
if ($(this).is(".selector"))
$('.all').not(this).prop("checked", false)
}
$("#Hidden").on("click", function() {
$(".selector").toggle();
});
});