【问题标题】:Checking the header checkbox when all the checkboxes in the table are checked选中表中的所有复选框时选中标题复选框
【发布时间】:2013-04-26 04:54:45
【问题描述】:

我希望在选中表中的所有复选框时选中标题复选框,并且即使未选中单个复选框,也应取消选中标题复选框..

<html>
<table id="table" style="height:350px;margin-left:1em;width:700px;">
    <!--this is my table header-->
    <tr style="display:table-row">
        <th class="checkbox"><input type="checkbox"/></th>
        <th class="Name">NAME</th>
        <th class="Score">SCORE</th>
        <th class="Email">EMAIL</th>
        <th class="Empty"></th>
    </tr>
    <tr>
        <!--tabledata-->
        <td ><input type="checkbox" /></td>
        <td >Vijay Prakash</td>
        <td >34</td>
        <td >vijay@gmail.com</td>
        <td ></td>
    </tr>
    <tr>
        <!--tabledata-->
        <td ><input type="checkbox" /></td>
        <td >Sashi Pagadala</td>
        <td >21</td>
        <td >sashi@gmail.com</td>
        <td ></td>
    </tr>
</table>
<input type="button" id="btnCalculate" value="Calculate"/>
<label>Average:</label>
<label id="lblAverage"></label>
<label>Max:</label>
<label id="lblMax"></label>
</form>
</html>

【问题讨论】:

  • 使用 jquery.........

标签: jquery html checkbox html-table


【解决方案1】:

看看这是不是你要找的。​​p>

Demo

$('td input:checkbox').change(function(){
    $('th.checkbox :checkbox').prop('checked',$('td input:checkbox:checked').length == $('td input:checkbox').length);
});

【讨论】:

  • @BharatBhushan 没问题..如果您对答案感到满意,请标记为答案。 :)
  • 我在表格外有一个文本框......用户在其中输入了一些人名,该名字出现在表格“NAME”列中......我们可以突出显示所有具有相同的表格单元格吗值作为文本框?
猜你喜欢
  • 2014-06-20
  • 1970-01-01
  • 2019-11-24
  • 1970-01-01
  • 2020-07-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多