一个什么都学的老程序员  
C#和PHP学习历程

JQuery.js是一个不可多得的JS框架,只要使用你就会迷上它,这里可以看到它的基础教程
http://wiki.jquery.org.cn/doku.php


<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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" >
<head runat="server">
    <title>JQuery实现全选和反选</title>
    <script language="javascript" type="text/javascript" src="js/jquery-1.2.1.pack.js"></script>
    <script type="text/javascript">
    function CheckAll()
    {
        //取消反选的选中状态
        if($("#otherCheck")[0].checked)
        {
            $("#otherCheck")[0].checked=false;
        }
        if($("#allCheck")[0].checked)
        {
            //从div1中获取所有属性type=checkbox的input元素
            $('#div1 input[@type=checkbox]').each(function(i)
            {
                this.checked=true;
            });
        }
        else
        {
            $('#div1 input[@type=checkbox]').each(function(i)
            {
                this.checked=false;
            });
        }
       
    }
    function CheckOther()
    {
    //取消全选的选中状态
        if($("#allCheck")[0].checked)
        {
            $("#allCheck")[0].checked=false;
        }
        if($("#otherCheck")[0].checked)
        {
            $('#div1 input[@type=checkbox]').each(function(i)
            {
                if(this.checked)
                {
                    this.checked=false;
                }
                else
                {
                    this.checked=true;
                }
               
            });
        }
        else
        {
             $('#div1 input[@type=checkbox]').each(function(i)
            {
                if(this.checked)
                {
                    this.checked=false;
                }
                else
                {
                    this.checked=true;
                }
               
            });
        }
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div id="div1">
        <input type="checkbox"/>A<br />
        <input type="checkbox"/>B<br />
        <input type="checkbox"/>C<br />
        <input type="checkbox"/>D<br />
        <input type="checkbox"/>E<br />
        <input type="checkbox"/>F<br />
        <input type="checkbox"/>G<br />
        </div>
        <div id="div2">
        <input type="checkbox" id="allCheck" onclick="CheckAll();" />全选
        &nbsp;&nbsp
        <input type="checkbox" id="otherCheck" onclick="CheckOther();" />反选
        </div>
    </div>
    </form>
</body>
</html>

posted on 2008-03-07 11:18  剑落飘香  阅读(5613)  评论(4编辑  收藏  举报