I have a some checkbox with each value .I want to auto checked of checkbox . I use logic & in this case , but it's not working. Example : value sum = 5 : food and water is checked , sum = 4 : water is checked, sum = 3 : candy and food is checked , ....
var sum = 5;
var list = document.getElementsByClassName("checkbox1");
for (var i = 0; list[i]; ++i)
{
if ( (sum & list[i].val()) == list[i].val() )
{
$(this).prop('checked', true);
}
}
<table id="div_table">
<tbody>
<tr>
<td>
<input type="checkbox" class="checkbox1" id="candy" value="2" />
</td>
<td>Candy</td>
</tr>
<tr>
<td>
<input type="checkbox" class="checkbox1" id="food" value="1" />
</td>
<td>Food</td>
</tr>
<tr>
<td>
<input type="checkbox" class="checkbox1" id="water" value="4" />
</td>
<td>Water</td>
</tr>
</tbody>
</table>
Thank guys.
Aucun commentaire:
Enregistrer un commentaire