2016-11-28 2 views
0

確認し、これらの私は、私は、ユーザーがページ上で確認することができ、チェックボックスの数を制限することができますjqueryののビットがありますリミットのチェックボックスだけ新しく

$('input[type=checkbox]').on('change', function (e) { 
    if ($('input[type=checkbox]:checked').length > 3) { 
     $(this).prop('checked', false); 
     alert("allowed only 3"); 
    } 
}); 

をしかし、ユーザーは「X」の数に制限されています1日に1回彼らはフォームに来て、彼らの限界(3チェック)を提出します。

checked="checked" disabled="disabled" disabled/> 

文が言っている場合、私を修正する方法がある「入力[タイプ=チェックボックス]:チェックする」ではなく、彼らは昨日からのものであったが、無効に設定されている私は3はチェックして、次の日に戻ってきますclass = "disabled"の場合は無効にします。そうしないと、1日の制限にはカウントされません。

+0

を使用することができますか? –

+0

このサーバー側を確認していますか?これらの値は、ユーザーのブラウザで簡単に変更できます。 – circusdei

答えて

2

次のようにjQuery not()メソッドを使用できます。

$('input[type=checkbox]').on('change', function (e) { 
    if ($('input[type=checkbox]:checked').not(':disabled').length > 3) { 
     $(this).prop('checked', false); 
     alert("allowed only 3"); 
    } 
}); 
2

あなたは以前に確認チェックボックスを格納している:enabled

$('input[type=checkbox]').on('change', function (e) { 
    if ($('input[type=checkbox]:enabled:checked').length > 3) { 
     $(this).prop('checked', false); 
     alert("allowed only 3"); 
    } 
}); 
+0

":enabled:checked"と ":checked:"に比べて優位ですか?)( ':disabled') "? – Steve

+0

@Steve:シンプルさ?読みやすさ? –

+1

https://api.jquery.com/enabled-selector/ – BenG

関連する問題