Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在jQuery中使用复选框?_Javascript_Jquery_Html_Checkbox - Fatal编程技术网

Javascript 如何在jQuery中使用复选框?

Javascript 如何在jQuery中使用复选框?,javascript,jquery,html,checkbox,Javascript,Jquery,Html,Checkbox,我对jQuery中处理复选框的概念比较陌生。我有三个同名的复选框。现在我只想根据第一个复选框的选择应用一些条件。供您参考,我的HTML代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">

我对jQuery中处理复选框的概念比较陌生。我有三个同名的复选框。现在我只想根据第一个复选框的选择应用一些条件。供您参考,我的HTML代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
</head>
<body> 
<table>
  <tr>
    <td>
      <input type="checkbox" id="users"  value="users"/>Users 
    </td>
    <td>
      <input type="checkbox" id="upload_from_file" value="upload_from_file"/>Upload From File
    </td>
    <td>
      <input type="checkbox" id="copy_paste_from_excel" value="copy_paste_from_excel"/>Copy paste from excel
    </td>
  </tr>
  <tr>
    <td colspan="3">
      <h4>Users</h4>
        <input type="checkbox" class="user_checkbox" name="user_checkbox" id="all_users" value="all_users"/>all users &nbsp;&nbsp;
        <input type="checkbox" class="user_checkbox" name="user_checkbox" id="register_users" value="register_users"/>Register users &nbsp;&nbsp;
        <input type="checkbox" class="user_checkbox" name="user_checkbox" id="package_expired" value="package_expired"/>Package expired &nbsp;&nbsp;
        <input type="checkbox" class="user_checkbox" name="user_checkbox" id="inactive_from_last_month" value="inactive_from_last_month"/>Inactive from last month
    </td>
  </tr> 
</table>
</body>
</html>
我的要求是,当用户选中具有值用户的复选框时,他/她必须从具有值的复选框组中选择至少一个复选框注册用户、包过期、上个月不活动

另一个条件是,当用户选择具有值all_users的复选框时,应禁用来自同一组的所有其他复选框,即具有值Register_users、package_expired、inactive_from_last_month的复选框

还有一个条件是,当用户选中其中任何一个复选框时,应禁用“所有用户”复选框

有人能帮助我使用jQuery实现这个功能吗?提前谢谢。如果我在上述代码中出现错误,您可以更正我的代码。我还附上了UI的截图


如果jQuery库尚未包含,则只需将其包含到文件中。然后只需编写以下脚本,即可实现所需的功能:

<script type="text/javascript">$("#inactive_from_last_month" ).is(":checked")
$(function(){
  $(".user_checkbox").click(function(){ 
    if($("#all_users" ).is(":checked")) {
      $("#register_users").removeAttr("checked");
      $("#package_expired").removeAttr("checked");
      $("#inactive_from_last_month").removeAttr("checked");
    } else if ($("#register_users" ).is(":checked") || $("#package_expired" ).is(":checked") || $("#inactive_from_last_month" ).is(":checked")) {
      $("#all_users").removeAttr("checked"); }
    });
});
</script>

不要在一个页面或表单上多次使用相同的id和名称。因此不是一个网站,请为我编码。。。雇佣一名开发人员或尝试自己学习/实践。如果你被困在某个地方,只需问一个问题。这可能是重复的