2013-04-12 29 views
1

特定類作爲這個問題的延續 - 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); 
     } 
    } 
} 
}); 
+0

我不明白你在問什麼。類的選擇器是最常見/最基本的jQuery選擇器之一 - 它只是'.correct'。你想在哪裏添加它?你有什麼疑問? – drquicksilver

回答

2

試試這個:

$("input[type=checkbox].correct").click(function (e) { 
     if ($(e.currentTarget).closest("div.question").length > 0) { 
      toggleInputs($(e.currentTarget).closest("div.question")[0]);   
     } 
    }); 
0
var $checkboxes = $('input.correct:checkbox"); 
+0

我認爲這隻適用於css3 –