简体   繁体   中英

How to iterate through table with and get each checkbox value

i have this table :

<table ="myTable">
<tr>
<td id="username_57">lillie</td>
<td id="text_57"/>
<td>1969-12-31</td>
<td>24.xx.84.xx</td>
<td>
<button id="edit_text_57" name="id_57">Edit</button>
<input type="checkbox" id="delit_57"/>
</td>
</tr>
<tr>
<td id="username_39">test</td>
<td id="text_39">asdasdasdsdasdasd</td>
<td>2012-06-04</td>
<td>217.xx.237.6</td>
<td>
<button id="edit_text_39" name="id_39">Edit</button>
<input type="checkbox" id="delit_39"/>
</td>
</tr>
<tr>
<td id="username_45">admin</td>
<td id="text_45">sadasdasdad</td>
<td>2012-09-04</td>
<td>217.xx.237.6</td>
<td>
<button id="edit_text_45" name="id_45">Edit</button>
<input type="checkbox" id="delit_45"/>
</td>
</tr>
</table>

i like to iterate through all the checkbox's with the id delit_* and check if its value is checked or not? how can i do this in jquery style ?

A selector can actually return the ones that are checked. Iteration is not needed.

$('input[type="checkbox"][id^="delit_"]:checked').each(function()
{
// Do something.
});

If you want checked and unchecked, simply remove the :checked part of the selector, and compare if (this.checked) { } in the .each loop.

jsFiddle: http://jsfiddle.net/jimp/rKjtr/

$("input[type=checkbox][id^='delit']").each(function(){
   if  (this.checked)
   {
     // do your stuff here
   }
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM