<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script>
//
function test1() {
var divs = document.querySelectorAll("div");
arr = Array.prototype.slice.call(divs);
var locationArr = [];
for (var i = 0; i < arr.length; iPP) {
if (arr[i].indexOf("li") >= 0) {
locationArr.push(i);
}
}
console.log(arr);
console.log(locationArr); //
}
//
function test2() {
var arr = ["zhao", "qian", "sun", "li", "zhou"];
var locationArr = [];
for (var i = 0; i < arr.length; iPP) {
if (arr[i].indexOf("li") >= 0) {
locationArr.push(i);
}
}
console.log(arr);
console.log(locationArr); //
}
</script>
</head>
<body>
<button onclick="test1()"></button>
<button onclick="test2()"></button>
<div id="rongqi">
<div>zhao</div>
<div>qian</div>
<div>sun</div>
<div>li</div>
<div>zhou</div>
</div>
</body>
</html>