zoukankan      html  css  js  c++  java
  • 多选checkbox

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <script  src="jquery.min.js"></script>
    </head>
    <body>
        <form id='myForm' name="myForm" method="post" action="test6.php">
    <input type="checkbox" id='all' >:全部</input>

    <input type="checkbox" class="list" name='list[]' value="1" >:1</input>

             <input type="checkbox" class="list" name='list[]' value="2" >:2</input>
             <input type="checkbox" class="list" name='list[]' value="3" >:3</input>

            <br/>
            <br/>
            <select name="select">
                <option>1</option>
                <option>2</option>
                <option>3</option>
            </select>
            <input type="button" id="but" value="sub"></input>
            <input type="submit" id="but" value="sub12"></input>
        </form>
    </body>
    </html>
    <script type="text/javascript">
        $(document).ready(function($) {    
            $("#all").click(function(event) {
                if($('#all').prop('checked')){
                    $('.list').prop('checked',true);
                }else{
                    $('.list').prop('checked',false);
                }
            });
            $(".list").click(function(event) {
                var arr_stu = [];
                $('.list').each(function(index, el) {
                    var statu = $(this).prop('checked');
                    arr_stu.push(statu);
                });
                $.unique(arr_stu).length==1?$('#all').prop('checked',true):$('#all').prop('checked',false);
            });
    
            $('#but').click(function(){
                var data = $('#myForm').serialize();
                $.ajax({
                    url: 'test6.php',
                    type: 'post',
                    dataType: 'json',
                    data: data,
                    success:function(result){
    
                    }
                })
                
            })
        });
    </script>
  • 相关阅读:
    C 标准库
    C 标准库
    C 标准库
    C 标准库
    Chrome内核保存为mhtml(单网页)
    C 标准库
    C 标准库
    【转】AOP
    [转]控制反转与依赖注入模式
    [转]乐观锁、悲观锁、死锁的区别
  • 原文地址:https://www.cnblogs.com/kevin2016/p/7464405.html
Copyright © 2011-2022 走看看