如果调用函数的过程中数组越界就会报错。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script>
window.onload = function () {
for (i = 0; i < 10; i++) {
console.log(i);
}
name1 = document.getElementsByTagName("li");
console.log(name1.length);
for (var num = 0; num < name1.length; num++) {
console.log(num);
name1[num].style.color = "red";
}
console.log(i);
say(5);
};
function say(num) {
console.log("111");
if (num == 5) {
console.log("1111");
//你kin你擦,for循环的执行顺序都忘记了,害自己找了半天 执行完成里面的再i++再比较,所以最后j还是可以为3,但是为3的时候不会执行里面的内容。
for (var j = 0; j < 3; j++) {
// alert("nihao");
console.log(j);
}
name1[3].onmouseover = function () {
console.log(this.innerHTML);
};
}
console.log("hhhh");
console.log(name1[0]);
console.log(name1[1]);
console.log(name1[2]);
console.log(name1[3]);
console.log(name1[7]);
}
</script>
</head>
<body>
<ul>
<li>ni</li>
<li>hao</li>
<li>shi</li>
<li>jie</li>
</ul>
</body>
</html>
http://www.liangshunet.com/ca/201406/984360663.htm