就是选中复选框后,点击按钮操作勾选框内容

解决方案 »

  1.   


    <!DOCTYPE html>
    <html>
    <head>
        <title>wu</title>
    </head>
    <body>
        <div>
            <input type="checkbox" name="test" value="0" />0
            <input type="checkbox" name="test" value="1" />1
            <input type="checkbox" name="test" value="2" />2
            <input type="checkbox" name="test" value="3" />3
            <input type="checkbox" name="test" value="4" />4
            <input type="checkbox" name="test" value="5" />5
            <input type="checkbox" name="test" value="6" />6
            <input type="checkbox" name="test" value="7" />7 
            <br>
            <input type="button" id="btn" value="遍历" onclick="jqchk()" />
        </div>
        <script src="../js/jquery.min.js"></script>
        <script type="text/javascript">
            function jqchk() { 
                var chk_value = [];
                $('input[name="test"]:checked').each(function () {
                    //在这里面操作复选框的值
                    chk_value.push($(this).val());
                });
                alert(chk_value.length == 0 ? '你还没有选择任何内容!' : chk_value);
            }
        </script>
    </body>
    </html>
      

  2.   

    "<input type='checkbox'" + "name='checkBox'"+"onclick='chkClick()'"+">"
     <input class="btn btn-primary btn-sm" type="button" value="批量打回" onclick="chkClick()"  disabled="disabled" />
    function chkClick(){
    var chk_value=[];
    $('input[name="checkBox"]:checked').each(function(){
    chk_value.push($(this).val());
    if(chk_value.length==true){
    document.getElementById("button1").disabled="";

    }
    });
    if(chk_value.length==false){
    document.getElementById("button1").disabled="disabled";
    }
    alert("点击!");
    }
    我这样点按钮还是点勾选框都会出现“点击”。怎么能让只有点按钮出啊?这个“点击”部分我是准备写操作勾选数据的代码的,谢谢大神
      

  3.   

    "<input type='checkbox'" + "name='checkBox'"+"onclick='chkClick()'"+">"
     <input class="btn btn-primary btn-sm" type="button" value="批量打回" onclick="chkClick()"  disabled="disabled" />
    function chkClick(){
    var chk_value=[];
    $('input[name="checkBox"]:checked').each(function(){
    chk_value.push($(this).val());
    if(chk_value.length==true){
    document.getElementById("button1").disabled="";

    }
    });
    if(chk_value.length==false){
    document.getElementById("button1").disabled="disabled";
    }
    alert("点击!");
    }
    我这样无论点按钮还是勾选框都会出现“点击”,怎么只让点按钮出现“点击”?