JavaScript 有用的函数

控制网页前进/后退

history.forward();
history.back();

选择元素点击

// https://yihui.org/
var topBar = document.getElementsByTagName("a");
console.log(topBar[3].href);
topBar[3].click();

var x = document.getElementsByClassName("UnderlineNav-item");
console.log(x);
x[0].click();

for循环

cars = [1,2,3,4,5,6]
for (var i=0; i<cars.length; i++)
{ 
    console.log(i);
}

var mycars = new Array(); # 创建数组
mycars[0] = "Saab";
mycars[1] = "Volvo";
mycars[2] = "BMW";

for (var i=0; i< mycars.length; i++) {
  console.log(mycars[i]);
}
posted @ 2020-11-28 11:57  illmatic  阅读(30)  评论(0编辑  收藏  举报