Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.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_Html_Checkbox - Fatal编程技术网

javascript复选框全部选中

javascript复选框全部选中,javascript,jquery,html,checkbox,Javascript,Jquery,Html,Checkbox,我正在开发一个全选按钮,但我对javascript有点太不熟悉,无法完成这一部分 本质上,我在页面顶部有一个复选框,当您选中它时,它会在要选中的表的每一行中通过并更改一个复选框 我看了一下周围类似的问题,我知道我必须使用 ~~~~.prop('checked', ...) 这是我希望选中表中所有框的复选框 <div class="disc-opt" style="float:left"> Adjust All

我正在开发一个全选按钮,但我对javascript有点太不熟悉,无法完成这一部分

本质上,我在页面顶部有一个复选框,当您选中它时,它会在要选中的表的每一行中通过并更改一个复选框

我看了一下周围类似的问题,我知道我必须使用

~~~~.prop('checked', ...)
这是我希望选中表中所有框的复选框

    <div class="disc-opt" style="float:left">
        Adjust All            
        <div class="make-switch">
            <input type="checkbox" class="create-adjustments"  />
        </div>
    </div>
我已经能够通过document.ready函数访问表行中的元素,但是当我选中复选框时,我无法获得任何工作

下面是我正在尝试做的事情的图片:

我正试图这样做,当我选中左上角的复选框时,它会遍历表格并选中右列中的所有复选框。

看看我之前做过类似的事情,这对我来说很有帮助。基本上,您可以创建一个包含所有输入框的div,并在单击主框时将所有输入框标记为选中

HTML:

看看我之前做过类似的事情,这对我来说很有帮助。基本上,您可以创建一个包含所有输入框的div,并在单击主框时将所有输入框标记为选中

HTML:


如果您谈论的是
~~~~.prop('checked',…)
,那么您谈论的是jQuery

在这种情况下,如果要选中复选框,则需要提供
ID
class
。如果你不想,那么:

$(".make-switch input:checkbox:first").prop('checked',true)

如果您谈论的是
~~~~.prop('checked',…)
,那么您谈论的是jQuery

在这种情况下,如果要选中复选框,则需要提供
ID
class
。如果你不想,那么:

$(".make-switch input:checkbox:first").prop('checked',true)

我最终用这个解决了它

if($("#create-adjustments").is(':checked'))
    {
        $("tr").find("td.box").find("div").find("div").prop('class', "switch-on switch-animate");
    } else {
        $("tr").find("td.box").find("div").find("div").prop('class', "switch-off switch-animate");

    }

我最终用这个解决了它

if($("#create-adjustments").is(':checked'))
    {
        $("tr").find("td.box").find("div").find("div").prop('class', "switch-on switch-animate");
    } else {
        $("tr").find("td.box").find("div").find("div").prop('class', "switch-off switch-animate");

    }
全选
复选框1
复选框2
复选框3
复选框4
$('.selectall')。单击(函数(){ 如果($(this).is(':checked'){ $('#checkboxlist输入[type=“checkbox”').prop('checked',true); }否则{ $('#checkboxlist input[type=“checkbox”').prop('checked',false); } });

全选
复选框1
复选框2
复选框3
复选框4
$('.selectall')。单击(函数(){ 如果($(this).is(':checked'){ $('#checkboxlist输入[type=“checkbox”').prop('checked',true); }否则{ $('#checkboxlist input[type=“checkbox”').prop('checked',false); } });

我刚刚在顶部添加了一些信息,我正在努力使其正常工作。我刚刚在顶部添加了一些信息,我正在努力使其正常工作。最佳做法是添加一个代码示例。链接的问题是,当你的书面摘要保留时,它会消失。链接仅作为注释有效,而不是答案。@AlexeyAyzin:I suG按照Thomas的建议,最好添加一个代码段。你的问题目前只是一个边缘链接。@Matt这更好吗?对不起,我花了一段时间才回到我的问题上。最好是添加一个代码示例。链接的问题是,当你的书面摘要留下时,它就消失了。链接只作为注释有效,而不是答案。@AlexeyAy吉娜:我建议按照托马斯的建议添加一个代码段。你的问题目前只是一个边缘链接。@马特,这样更好吗?对不起,我花了一段时间才回复
$(".make-switch input:checkbox:first").prop('checked',true)
if($("#create-adjustments").is(':checked'))
    {
        $("tr").find("td.box").find("div").find("div").prop('class', "switch-on switch-animate");
    } else {
        $("tr").find("td.box").find("div").find("div").prop('class', "switch-off switch-animate");

    }
<label><input type="checkbox" name="sample" class="selectall"/> Select all</label>

<div id="checkboxlist">

    <label><input type="checkbox" name="sample[]"/>checkbox1</label><br />
    <label><input type="checkbox" name="sample[]"/>checkbox2</label><br />
    <label><input type="checkbox" name="sample[]"/>checkbox3</label><br />
    <label><input type="checkbox" name="sample[]"/>checkbox4</label><br />

</div>

$('.selectall').click(function() {     
    if ($(this).is(':checked')) {        
        $('#checkboxlist input[type="checkbox"').prop('checked', true);
    } else {
        $('#checkboxlist input[type="checkbox"').prop('checked', false);
    }
});