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>
  • 相关阅读:
    今天面试一些程序员(新,老)手的体会
    UVA 10635 Prince and Princess
    poj 2240 Arbitrage
    poj 2253 Frogger
    poj 2485 Highways
    UVA 11258 String Partition
    UVA 11151 Longest Palindrome
    poj 1125 Stockbroker Grapevine
    poj 1789 Truck History
    poj 3259 Wormholes
  • 原文地址:https://www.cnblogs.com/kevin2016/p/7464405.html
Copyright © 2011-2022 走看看