<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div class="main>
<p class="item" id="14">24</p>
<p class="item" id="12">22</p>
<p class="item" id="13">2</p>
<p class="item" id="14">2</p>
</div>
</body>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
var arr = document.getElementsByClassName('item')
console.log(arr.length )
$('.item').each(function(index) {
alert(index + ': ' + $(this).text());
});
</script>
</html>
打印结果为啥是3,第一个为22,去掉main标签后就正确了,求原因
Smart猫小萌
相关分类