首页 > 代码库 > JQery遍历方法each

JQery遍历方法each

each遍历jquery对象

<script type="text/javascript" >
        function readmessage(){
            $("li").each(function(k,v){
                console.log(k+‘----------‘+v);
                v.style.color="red";
                //$(v).css(‘background‘,‘lightblue‘);
                
            });
        }
    </script>
 </head>
 <body>
  <ul>
        <li>巴西</li>
        <li>德国</li>
        <li>法国</li>
        <li>英格兰</li>
  </ul>
  <input type="button" value=http://www.mamicode.com/"触发" onclick="readmessage()"/>>