工作,爲什麼不Check all
工作時,我使用jQuery 2.1.3版本,檢查jsfiddle here檢查所有不jQuery的版本2.1.3
此代碼是工作的罰款與1.7.4。可能是切換不支持在2.1.3版本,我試圖與on.click
但沒有得到預期的結果。
$(document).ready(function(){
$('.check:button').toggle(function(){
$('input:checkbox').attr('checked','checked');
var count = $("input[type=checkbox]:checked").size();
$(this).val('uncheck all')
$("#count").text(count+ " item(s) selected");
},function(){
$('input:checkbox').removeAttr('checked');
var count = $("input[type=checkbox]:checked").size();
$(this).val('check all');
$("#count").text(count+ " item(s) selected");
}),
$("input[type=checkbox]").click(function() {
$("#count").html($("input[type=checkbox]:checked").length + " item(s) selected")
})
})
請指導。
感謝您的代碼,但控制檯提供此錯誤'空字符串傳遞給getElementById()。'。不知道爲什麼。但是代碼在2.1.3版本中完美工作。 – yuri1000