[英]Can someone tell me why this jQuery script does not work?
這是我的代碼。
function switchbox(showall, maincls) {
$(showall).change(function() {
if ($(this).is(":checked")) {
$(maincls).each(function(i) {
$(this).attr('disabled', true);
});
} else {
$(maincls).each(function(i) {
$(this).attr('disabled', false);
});
}
});
}
switchbox('.show-all-tags, .tags');
switchbox('.show-all-cats, .categories');
如果我沒有在函數中使用變量,它會起作用。 選中show-all-X時,它應禁用該類的所有復選框,反之亦然。 而且我嘗試了沒有變量showall,maincls的情況。 我在這里做錯了嗎?
謝謝。
maincls尚未定義,也許您的意思是:
switchbox('.show-all-tags', '.tags');
switchbox('.show-all-cats', '.categories');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.