多选框JQ控制

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh" dir="ltr">
<head profile="http://www.w3.org/2000/08/w3c-synd/#">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="keywords" content="Leo,HEnT Studio,LAMP,PHP,MySQL" />
    <meta name="DEscription" content="HEnT Studio" />
    <meta name="Author" content="Leo,HEnT Studio" />

    <title>New Page | xHTML1.0 Transitional</title>
    <link rel="shortcut icon" href="favicon.ico" />
    <!--CSS&JS is here
    <link rel="stylesheet" type="text/css" href="css.css" />
    <script type="text/javascript" src="js.js"></script>
    -->
    <script type="text/javascript" src="jquery-1.4.2.min.js"></script>
    <script>
        function test(){
            var leng=$("input:checked").length;
            var box=$("input:checked.fox").each(function(){//由于复选框一般选中的是多个,所以可以循环输出
                alert($(this).val());
            });
        }
        function selectall(){
            if($("#tree").attr("checked")==true){
                $("input[type=checkbox]").attr("checked",true);//打勾

            }else{
                $("input[type=checkbox]").attr("checked",'');//不打勾

            }
        }
    </script>
</head>
<body>
<input type="checkbox" id="tree" onclick="selectall(this)" />全选</br>
<input type="checkbox" class="fox" value="1" />1
<input type="checkbox" class="fox" value="2" />2
<input type="checkbox" class="fox" value="3" />3
<input type="checkbox" class="fox" value="4" />4</br>
<input type="button" value="提交" onclick="test(this)" />
</body>
</html>

 

posted on 2013-01-14 16:50  hrc  阅读(935)  评论(0)    收藏  举报