码迷,mamicode.com
首页 > Web开发 > 详细

jquery的each函数的用法

时间:2017-01-17 00:44:39      阅读:312      评论:0      收藏:0      [点我收藏+]

标签:head   read   span   pre   color   案例   map   ons   ext   

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>each和 map函数的使用案例</title>
    <script src="jquery-1.11.3.min.js"></script>
    <script>
    
        jQuery(document).ready(function($) {
            // $("li").each(function(index, el) {

            //     var originTxt = $(el).text();

            //     $(el).text(originTxt + index);
            // });

            $.each($("li"), function(i, e) {
                var originTxt = $(e).text();

                $(e).text(originTxt + i+1);

            });

            //map函数: 会把所有的
            // 全局的map 函数 参数 跟 jQuery对象的参数是反的。
            var temp = $.map($("li"), function(elme, index) {
                return index;
            });

            var temp2 = $("li").map(function(i, e){
                console.log(i);
                return i;
            });

        });

    </script>

</head>
<body>
    <ul>
        <li>大好时光</li>
        <li>大好时光</li>
        <li>大好时光</li>
        <li>大好时光</li>
    </ul>
</body>
</html>

 

jquery的each函数的用法

标签:head   read   span   pre   color   案例   map   ons   ext   

原文地址:http://www.cnblogs.com/mr-wuxiansheng/p/6291462.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!