1. 程式人生 > >學而時習之,不亦說乎!

學而時習之,不亦說乎!

 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        div
        {
            width: 140px;
            height: 140px;
            margin: 5px;
            background: #aaa;
            border: #000 1px solid;
            float: left;
            font-size: 17px;
            font-family: Verdana;
        }
        div.mini
        {
            width: 55px;
            height: 55px;
            background-color: #aaa;
            font-size: 12px;
        }
    </style>

    <script src="JS/jquery-1.3.2.js" type="text/javascript"></script>

    <script type="text/javascript">

        $(function() {
            $("#btn1").click(function() {
                $("body div").css("background", "#bbffaa");
            })
            $("#btn2").click(function() {
                $("body>div").css("background", "#bbffaa");
            })
        })
    </script>

</head>
<body>
   
    <div id="div1">
        <div id="div2" class="mini">
        </div>
    </div>
    <div id="div3">
        <div id="div4" class="mini">
        </div>
    </div>
    <input id="btn1" type="button" value="獲取所有body裡的div" onclick="" />
    <input id="btn2" type="button" value="獲取所有body裡子元素為div的" onclick="" />
  
</body>
</html>