[英]How to check/uncheck a checkbox while clicking a table row
I need to check/uncheck a checkbox that exist inside a row under table body when it is clicked anywhere within a row except a link. 我需要选中/取消选中表主体下一行中存在的复选框(当单击链接以外的行中的任何位置时)。 I tried to make it working by using jQuery's prop, but something is not working properly.
我试图通过使用jQuery的道具使其工作,但某些工作无法正常进行。
I have a table structure like below: 我有一个如下表结构:
<table id="anywhere_click">
<thead>
<tr>
<th><input type="checkbox" onclick="selectAll('myDataID[]');" /></th>
<th>Title</th>
<th>Details</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox" name="myDataID[]" value="1" /></td>
<td>Stackoverflow</td>
<td>Some text here....</td>
</tr>
<tr>
<td><input type="checkbox" name="myDataID[]" value="2" /></td>
<td>Google</td>
<td>
<a href="aaa.html">This is a Link</a><br />
Some text here....<br />
<img src="something.jpg" />
</td>
</tr>
<tr>
<td><input type="checkbox" name="myDataID[]" value="3" /></td>
<td>test</td>
<td>Some text here....</td>
</tr>
</tbody>
</table>
$('#anywhere_click tbody tr').click(function (e) {
if(!$(e.target).is('#anywhere_click td input:checkbox'))
$(this).find('input:checkbox').trigger('click');
});
$('#anywhere_click tr a').click(function (e) {
e.stopPropagation();
});
If you checked when the site 's loading. 如果您检查了网站的加载时间。
You have to add in the tag <td><input type="checkbox" name="myDataID[]" value="3" /></td>
checked. 您必须在
<td><input type="checkbox" name="myDataID[]" value="3" /></td>
的标签<td><input type="checkbox" name="myDataID[]" value="3" /></td>
。
<td><input type="checkbox" name="myDataID[]" value="3" checked /></td>
With the button you want checked and unchecked. 使用您要检查和取消检查的按钮。
Info: Information 信息: 信息
and example: Examble with button checked and unchecked 和示例: 选中并取消选中按钮的前导
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.