(041)jquery_dom选择器_each

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
  <head>
    <title>dom_each.html</title>
    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
    <style type="text/css">
        span
        {
            color: White;
            padding: 8px;
            margin: 5px;
            float: left;
        }
        .green
        {
            background-color: green;
        }
        .red
        {
            background-color: red;
        }
    </style>
    <script type="text/javascript" src="../js/jquery/jquery190.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("span").each(function(index){
                if(index == 2) {
                    $(this).css("background","blue");
                }
            });
        });
        
    </script>
  </head>
  
  <body>
        <h3>使用each()方法遍历元素</h3>
        <span class="green">香蕉</span>
        <span class="green">桃子</span>
        <span class="green">葡萄</span>
        <span class="green">荔枝</span>
  </body>
</html>

 

posted @ 2014-12-18 13:53  雪中飞雁  阅读(552)  评论(0)    收藏  举报