<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="../js/jquery-3.3.1.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(function () {
var citys = $("#city li"); /*for (var i = 0; i < citys.length; i++) {
alert(i + ":" + citys.innerHTML);
}*/
citys.each(function(index,element){
//第一种方式
//alert(this.innerHTML)
alert($(this).html())
//第二种方式
// alert(index+":"+element.innerHTML)
alert(index+":"+$(element).html())
});
});
</script>
</head>
<body>
<ul id="city">
<li>北京</li>
<li>上海</li>
<li>天津</li>
<li>重庆</li>
</ul>
</body>
</html>
|
|