为每个数组项添加一个点击
Add a click to each array item
所以我的问题是我希望脚本在控制台中简单记录后点击每个 class。
我尝试在几段代码之后添加一些 .click() 方法,但没有成功。
下面是代码
var array = ['.button.color.color-41d841', '.button.color.color-dc0000', '.button.color.color-1e00e9', '.button.color.color-ff6f00'];
var interval = 1000; // how much time should the delay between two iterations be (in milliseconds)?
array.forEach(function(el, index) {
setTimeout(function() {
console.log(el);
}, index * interval);
});
console.log('Loop finished.');
它只是打印元素的 class。
已解决
var array = ['.button.color.color-41d841', '.button.color.color-dc0000', '.button.color.color-1e00e9', '.button.color.color-ff6f00'];
var interval = 1000; // how much time should the delay between two iterations be (in milliseconds)?
array.forEach(function(el, index) {
setTimeout(function() {
console.log(el);
$(el).click()
}, index * interval);
});
console.log('Loop finished.');
需要调用下面的脚本
$(document).on('click',el,function(){});
因为你是动态绑定点击事件
var array = ['.label-key', '.button.color.color-dc0000', '.button.color.color-1e00e9', '.button.color.color-ff6f00'];
var interval = 1000; // how much time should the delay between two iterations be (in milliseconds)?
array.forEach(function (el, index) {
$(document).on('click',el,function(){});
setTimeout(function () {
console.log(el);
}, index * interval);
});
console.log('Loop finished.');
试试这个,你需要找到元素并点击它
var array = ['.button.color.color-41d841', '.button.color.color-dc0000', '.button.color.color-1e00e9', '.button.color.color-ff6f00'];
var interval = 1000; // how much time should the delay between two iterations be (in milliseconds)?
array.forEach(function (el, index) {
setTimeout(function () {
console.log(el);
document.querySelector(el).click()
}, index * interval);
});
所以我的问题是我希望脚本在控制台中简单记录后点击每个 class。
我尝试在几段代码之后添加一些 .click() 方法,但没有成功。
下面是代码
var array = ['.button.color.color-41d841', '.button.color.color-dc0000', '.button.color.color-1e00e9', '.button.color.color-ff6f00'];
var interval = 1000; // how much time should the delay between two iterations be (in milliseconds)?
array.forEach(function(el, index) {
setTimeout(function() {
console.log(el);
}, index * interval);
});
console.log('Loop finished.');
它只是打印元素的 class。
已解决
var array = ['.button.color.color-41d841', '.button.color.color-dc0000', '.button.color.color-1e00e9', '.button.color.color-ff6f00'];
var interval = 1000; // how much time should the delay between two iterations be (in milliseconds)?
array.forEach(function(el, index) {
setTimeout(function() {
console.log(el);
$(el).click()
}, index * interval);
});
console.log('Loop finished.');
需要调用下面的脚本
$(document).on('click',el,function(){});
因为你是动态绑定点击事件
var array = ['.label-key', '.button.color.color-dc0000', '.button.color.color-1e00e9', '.button.color.color-ff6f00'];
var interval = 1000; // how much time should the delay between two iterations be (in milliseconds)?
array.forEach(function (el, index) {
$(document).on('click',el,function(){});
setTimeout(function () {
console.log(el);
}, index * interval);
});
console.log('Loop finished.');
试试这个,你需要找到元素并点击它
var array = ['.button.color.color-41d841', '.button.color.color-dc0000', '.button.color.color-1e00e9', '.button.color.color-ff6f00'];
var interval = 1000; // how much time should the delay between two iterations be (in milliseconds)?
array.forEach(function (el, index) {
setTimeout(function () {
console.log(el);
document.querySelector(el).click()
}, index * interval);
});