Sto provando a disabilitare tutte le caselle di controllo non selezionate quando ci sono 5 caselle di controllo spuntate.Jquery come contare spunta e disattiva le caselle di controllo
Il mio codice non funziona qui è: http://jsfiddle.net/mtYtW/18/
mio Jquery:
var countchecked = $('table input[type="checkbox"]').find(":checked").length
if(countcheckhed > 5) {
$("table input:checkbox").attr("disabled", true);
} else {}
mio HTML:
<table cellspacing="0" cellpadding="0" width="770px;">
<tbody><tr style="border: 1px solid green; height: 40px; font-size: 14px;">
<th>Feature 1</th>
<th>Feature 2</th>
<th>Feuture 3</th>
</tr>
<tr>
<td class="checkit"><input type="hidden" value="0" name="search[windows_is_true]"><input type="checkbox" value="1" name="search[windows_is_true]" id="search_windows_is_true"></td>
<td>Test 1</td>
<td>Test 2</td>
<td>Test 3</td>
<td>Test 4</td>
<td>Test 5</td>
<td>Test 6</td>
</tr>
<tr>
<td class="checkit"><input type="hidden" value="0" name="search[windows_is_true]"><input type="checkbox" value="1" name="search[windows_is_true]" id="search_windows_is_true"></td>
<td>Test 1</td>
<td>Test 2</td>
<td>Test 3</td>
<td>Test 4</td>
<td>Test 5</td>
<td>Test 6</td>
</tr>
<tr>
<td class="checkit"><input type="hidden" value="0" name="search[windows_is_true]"><input type="checkbox" value="1" name="search[windows_is_true]" id="search_windows_is_true"></td>
<td>Test 1</td>
<td>Test 2</td>
<td>Test 3</td>
<td>Test 4</td>
<td>Test 5</td>
<td>Test 6</td>
</tr>
<tr>
<td class="checkit"><input type="hidden" value="0" name="search[windows_is_true]"><input type="checkbox" value="1" name="search[windows_is_true]" id="search_windows_is_true"></td>
<td>Test 1</td>
<td>Test 2</td>
<td>Test 3</td>
<td>Test 4</td>
<td>Test 5</td>
<td>Test 6</td>
</tr>
<tr>
<td class="checkit"><input type="hidden" value="0" name="search[windows_is_true]"><input type="checkbox" value="1" name="search[windows_is_true]" id="search_windows_is_true"></td>
<td>Test 1</td>
<td>Test 2</td>
<td>Test 3</td>
<td>Test 4</td>
<td>Test 5</td>
<td>Test 6</td>
</tr>
<tr>
<td class="checkit"><input type="hidden" value="0" name="search[windows_is_true]"><input type="checkbox" value="1" name="search[windows_is_true]" id="search_windows_is_true"></td>
<td>Test 1</td>
<td>Test 2</td>
<td>Test 3</td>
<td>Test 4</td>
<td>Test 5</td>
<td>Test 6</td>
</tr>
<tr>
<td class="checkit"><input type="hidden" value="0" name="search[windows_is_true]"><input type="checkbox" value="1" name="search[windows_is_true]" id="search_windows_is_true"></td>
<td>Test 1</td>
<td>Test 2</td>
<td>Test 3</td>
<td>Test 4</td>
<td>Test 5</td>
<td>Test 6</td>
</tr>
<tr>
<td class="checkit"><input type="hidden" value="0" name="search[windows_is_true]"><input type="checkbox" value="1" name="search[windows_is_true]" id="search_windows_is_true"></td>
<td>Test 1</td>
<td>Test 2</td>
<td>Test 3</td>
<td>Test 4</td>
<td>Test 5</td>
<td>Test 6</td>
</tr>
<tr>
<td class="checkit"><input type="hidden" value="0" name="search[windows_is_true]"><input type="checkbox" value="1" name="search[windows_is_true]" id="search_windows_is_true"></td>
<td>Test 1</td>
<td>Test 2</td>
<td>Test 3</td>
<td>Test 4</td>
<td>Test 5</td>
<td>Test 6</td>
</tr>
<tr>
<td class="checkit"><input type="hidden" value="0" name="search[windows_is_true]"><input type="checkbox" value="1" name="search[windows_is_true]" id="search_windows_is_true"></td>
<td>Test 1</td>
<td>Test 2</td>
<td>Test 3</td>
<td>Test 4</td>
<td>Test 5</td>
<td>Test 6</td>
</tr>
<tr>
<td class="checkit"><input type="hidden" value="0" name="search[windows_is_true]"><input type="checkbox" value="1" name="search[windows_is_true]" id="search_windows_is_true"></td>
<td>Test 1</td>
<td>Test 2</td>
<td>Test 3</td>
<td>Test 4</td>
<td>Test 5</td>
<td>Test 6</td>
</tr>
</tbody></table>
Si prega di aggiungere il codice alla domanda pure. Per il futuro, se jsfiddle scomparirà, la domanda sarà comunque pertinente. –
Il je fiddle che hai fornito passa semplicemente il codice onload e quindi non controlla mai più. Prova a ottenere tutte le caselle di controllo e aggiungere un attributo .click e rivalutare il conteggio degli assegni. –
countchecked è errato. – Narnian