简体   繁体   中英

Read Checkbox checked property from HTML

I have an aspx page which renders as below.

<div id="div1">
<tr>
<td>SomeTxt</td>
<td><input checked="checked" class="check-box" disabled="disabled" type="checkbox" /></td>
<td>text2</td>
</tr>
</div>

Iam trying to read checkbox checked property from javascript :

var status = $('#div1 tbody tr:eq(' + tr.rowIndex + ') td:eq(1)').checked;

But I am getting undefined.

使用is(':checked')

var status = $('#div1 input[type="checkbox"]').is(':checked');

Something like this

var status = $("input[type='checkbox']:checked").val();
alert(status);

TD将不具有选中的属性,必须选择输入元素。

you can use:

$("#yourID").is(":checked")

Make sure give an ID to your checkbox, not taking it <tr>

td:eq(1) will return td and not the input element

var status = $('#div1 tbody tr:eq(' + tr.rowIndex + ') td:eq(1)').find("input").get(0).checked;

Regards,

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