简体   繁体   English

如何在单击表格行时选中/取消选中复选框

[英]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.

相关问题 单击jqgrid中的行时如何取消选中复选框? - How to uncheck checkbox when clicking on row in jqgrid? 如何通过单击包含它的 div 来选中/取消选中复选框? - How to check/uncheck a checkbox by clicking a div that contains it? 单击表行时选中和取消选中复选框 - Check and Uncheck Checkbox when Table Row is Clicked 如果选中/取消选中,如何调整数据表复选框 - how to condition data table checkbox if check/uncheck 如何通过单击特定块外部来选中/取消选中复选框? - How to check/uncheck checkbox by clicking outside specific block? 如何在 Vue 3 中配置复选框输入以在单击图像时选中/取消选中 - How to configure checkbox input in Vue 3 to check/uncheck when clicking image 当我们选中和取消选中其他表中的复选框时,如何在jquery中的表中添加/删除行? - How to Add/remove row in table in jquery when we check and uncheck the checkbox in other table? 在表的上一行调用clone()方法时,如何取消选中clone()方法中的复选框? - How to uncheck the checkbox in a clone() method while calling clone() method on the previous row of table? 带输入复选框的表选中/取消选中 - Table with input checkbox check/Uncheck 单击后复选框不希望选中或取消选中 - Checkbox does not want to check or uncheck after clicking
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM