2014-01-09 54 views
0

删除复选框,我有如下一个HTML表格:有一个“无效”状态

<table> 
    <thead> 
     <tr> 
     <th><input type="checkbox" id="selectall" /></th> 
     <th colspan="2">Status</th> 
     <th class="data-name">UserName</th> 
     <th class="data-name">Description</th> 
    </thead> 
</table> 

的状态使用文本来指示活跃和不活跃用户。在这里,我试图显示一个错误消息,如果有人试图删除状态为'active'的复选框。只有“不活跃”的用户才能被删除。 我正在寻找一个jQuery代码。有人能帮我吗? 我提供了一个我想要实现的sudo代码。这可能在语法上不正确。

if $('#selectall input[type="checkbox"]:checked') is 'active' 
{ 
    alert('do not delete the checkbox'); 
} 
else 
{ 
    alert('delete the checkbox'); 
} 
+1

而这是哪里'active'和'inactive'文本? – adeneo

+1

您的意思是...... **残疾人** ** – Cilan

+0

为什么不只是禁用复选框,如果该行是“活动的”,阻止它首先被检查?这将为用户提供更明确的方向。 –

回答

0

这可能做到在JavaScript和HTML

http://jsfiddle.net/jHpKB/1/

我希望你帮

if ($('#selectall input[type="checkbox"]:checked').size() > 0) 
{ 
    alert('do not delete the checkbox'); 
} 
else 
{ 
    alert('delete the checkbox'); 
} 
0

我开发了他的下一个代码(我的英文不好对不起)

HTML

<table> 
    <thead> 
     <tr> 
     <th><input type="checkbox" id="selectall" /></th> 
     <th colspan="2">Status</th> 
     <th class="data-name">UserName</th> 
     <th class="data-name">Description</th> 
     </tr> 

    </thead> 
    <tbody> 
     <tr> 
      <td><input type="checkbox" data-user-id="1" data-status="active" /></td> 
      <td>Active</td> 
      <td>User 1</td> 
      <td>None</td>   
     </tr> 
     <tr> 
     <td><input type="checkbox" data-user-id="1" data-status="inactive" /></td> 
      <td>Inactive</td> 
      <td>User 1</td> 
      <td>None</td>   
     </tr> 

    </tbody> 
</table> 

的Javascript

$(document).ready(function(){ 
    $("#selectall").on("click", function(){ 
     var checked = $(this).is(":checked"); 

     $("input[type='checkbox'][data-status='inactive']").attr("checked", checked) 

    }); 
});