Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.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 复选框列表在单击“仅工作”时检查所有项目一次_Javascript_Jquery_Asp.net - Fatal编程技术网

Javascript 复选框列表在单击“仅工作”时检查所有项目一次

Javascript 复选框列表在单击“仅工作”时检查所有项目一次,javascript,jquery,asp.net,Javascript,Jquery,Asp.net,我有checkBoxList包含月数,当用户单击check all我有此HTML时,我需要检查此列表中的所有项目: <asp:CheckBox ID="cbAllYears" Text="All Years" runat="server" /> <asp:CheckBoxList ID="cblstMonthAvailability" runat="server" RepeatDirection="Horizontal">

我有checkBoxList包含月数,当用户单击check all我有此HTML时,我需要检查此列表中的所有项目:

<asp:CheckBox ID="cbAllYears" Text="All Years" runat="server" />


   <asp:CheckBoxList ID="cblstMonthAvailability" runat="server" RepeatDirection="Horizontal">
                    <asp:ListItem Text="Jan" Value="1"></asp:ListItem>
                    <asp:ListItem Text="Feb" Value="2"></asp:ListItem>
                    <asp:ListItem Text="Mar" Value="3"></asp:ListItem>
                    <asp:ListItem Text="Apr" Value="4"></asp:ListItem>
                    <asp:ListItem Text="May" Value="5"></asp:ListItem>
                    <asp:ListItem Text="Jun" Value="6"></asp:ListItem>
                    <asp:ListItem Text="Jul" Value="7"></asp:ListItem>
                    <asp:ListItem Text="Aug" Value="8"></asp:ListItem>
                    <asp:ListItem Text="Sep" Value="9"></asp:ListItem>
                    <asp:ListItem Text="Oct" Value="10"></asp:ListItem>
                    <asp:ListItem Text="Nov" Value="11"></asp:ListItem>
                    <asp:ListItem Text="Dec" Value="12"></asp:ListItem>
                </asp:CheckBoxList>

这是我的Jquery代码,它只在第一次单击时才起作用

<script type="text/javascript">
        $(document).ready(function () {
            $("#cbAllYears").bind("click", function () {
                $("INPUT[id^='cblstMonthAvailability']").attr("checked", $(this).is(":checked"));
            });
        });
    </script>

$(文档).ready(函数(){
$(“cbAllYears”).bind(“单击”,函数(){
$(“INPUT[id^='cblstmonthavability']”)attr(“选中的”,$(this.is)(:选中的”);
});
});
谢谢。

试试这个:

 $(document).ready(function () {
     $('[id$=cbAllYears"]').change(function (e) {
       $("input[id^='cblstMonthAvailability']").attr("checked", $(this).is(":checked"));
       return false
     });
 });
试试这个:

 $(document).ready(function () {
     $('[id$=cbAllYears"]').change(function (e) {
       $("input[id^='cblstMonthAvailability']").attr("checked", $(this).is(":checked"));
       return false
     });
 });

我建议将类添加到
checkbox
元素中,并使用jquery,如:

$(“#cbAllYears”)。在(“单击”,函数(){
$(“.month”).prop(“选中”),$(this.prop(“选中”);
});

全部的
简
二月
破坏
四月
也许
六月
七月
八月
九月
十月
十一月

Dec
我建议在
复选框中添加一个类,并使用jquery,如:

$(“#cbAllYears”)。在(“单击”,函数(){
$(“.month”).prop(“选中”),$(this.prop(“选中”);
});

全部的
简
二月
破坏
四月
也许
六月
七月
八月
九月
十月
十一月

Dec
由于
复选框列表
是服务器端控件,因此name属性将随Id一起更改。一种方法是按照@Alex的建议添加一个类。此外,您还可以在由CheckBoxList呈现的表中找到所有复选框,如下所示:-

$(document).ready(function () {
   $("#cbAllYears").click(function () {
       $('input[type="checkbox"]', $("#cblstMonthAvailability")).prop("checked",$(this).prop("checked"));
   });
});

由于
CheckBoxList
是服务器端控件,因此name属性将随Id一起更改。一种方法是按照@Alex的建议添加一个类。此外,您还可以在由CheckBoxList呈现的表中找到所有复选框,如下所示:-

$(document).ready(function () {
   $("#cbAllYears").click(function () {
       $('input[type="checkbox"]', $("#cblstMonthAvailability")).prop("checked",$(this).prop("checked"));
   });
});

我正在使用复选框列表,无法为复选框列表添加类Elements@MohammedAlasa'ad-您可以使用
CssClass
属性。我使用复选框列表,无法为复选框列表添加类Elements@MohammedAlasa'广告-您可以使用
CssClass
属性。请不要发布“尝试此操作,然后是一堆代码”的答案。添加一些单词/句子来解释问题的具体原因以及解决方案的解决方法。请不要发布“尝试此方法,然后是一堆代码”的答案。添加几个单词/句子来解释问题的具体内容以及解决方案是如何解决的