特定類作爲這個問題的延續 - Find checkboxes that are checked with a specific class定位與.find
是否有可能做同樣與這個jQuery - 我只是想專門針對與類「正確」的複選框上輸入?
jQuery(function($) {
$(document).ready(function() {
$("input[type=checkbox]").click(function (e) {
if ($(e.currentTarget).closest("div.question").length > 0) {
toggleInputs($(e.currentTarget).closest("div.question")[0]);
}
});
});
function toggleInputs(questionElement) {
if ($(questionElement).data('max-answers') == undefined) {
return true;
} else {
maxAnswers = parseInt($(questionElement).data('max-answers'), 10);
if ($(questionElement).find(":checked").length >= maxAnswers) {
$(questionElement).find(":not(:checked)").attr("disabled", true);
} else {
$(questionElement).find("input[type=checkbox]").attr("disabled", false);
}
}
}
});
我不明白你在問什麼。類的選擇器是最常見/最基本的jQuery選擇器之一 - 它只是'.correct'。你想在哪裏添加它?你有什麼疑問? – drquicksilver