引用js

<script language="javascript" src="jquery-1.10.2.js"></script>

js

    <script type="text/javascript">
        $(function () {
            var $citys = $("#cityname li");
            //for 循环
            for (i = 0; i < $citys.length; i++) {
                alert($citys[i].innerHTML);
            }
            //$().each(function(index,element)); index:当前下标  element:遍历的对象
            $citys.each(function (index, element) {
                alert(index + " " + element.innerHTML);
            });
            //$.each(obj,function(index,element));  index:当前下标  element:遍历的对象
            $.each($citys, function (index, element) {
                alert(index + " " + element.innerHTML);
            });
        });
    </script>

html

<ul id="cityname">
        <li>
            东莞
        </li>
        <li>
            深圳
        </li>
        <li>
            广州
        </li>
</ul>

 

 posted on 2019-04-25 09:58  会飞的金鱼  阅读(145)  评论(0)    收藏  举报