日期:2014-05-16  浏览次数:20356 次

关于js遍历节点并赋值编号
本帖最后由 zgj901528 于 2013-11-26 15:40:38 编辑
<div>
<div class="typecode1">
<div class="testtype">
<div class="imge_number"></div>
</div>
</div>
<div class="typecode2">
<div class="testtype">
<div class="imge_number"></div>
</div>
</div>
<div class="typecode3">
<div class="testtype">
<div class="imge_number"></div>
</div>
</div>
<div class="typecode4">
<div class="testtype">
<div class="imge_number"></div>
</div>
</div>
<div class="typecode5">
<div class="testtype">
<div class="imge_number"></div>
</div>
</div>
<div class="typecode6">
<div class="testtype">
<div class="imge_number"></div>
</div>
</div>
</div>

我想统计当前页面所有class="imge_number"的个数,然后给它加上编号。
第一个<div class="imge_number"></div>显示1.。依次排序
js

------解决方案--------------------
 jquery方法
$(".imge_number").each(function(i){
$(this).text(i+1);
})
------解决方案--------------------

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>RunJS</title>
<script id="jquery_183" type="text/javascript" class="library" src="/js/sandbox/jquery/jquery-1.8.3.min.js"></script>
</head>
<body>
<input type="button" value="xx" id="btn" />

<div>
        <div class="typecode1">
            <div class="testtype">
                <div class="imge_number"></div>
            </div>
        </div>
        <div class="typecode2">
            <div class="testtype">
                <div class="imge_number"></div>
       &n