我想根据部分填充网格,例如第一部分,第二部分,第三部分等等,我为每个部分创建了一个变量,以便用我的数组填充,其值分别为1到7 。
现在我创建了一个“函数”,我为每个section变量添加了for
,但之后我不知道如何运行Array.from
函数来填充每个部分有价值观。
var one = document.querySelectorAll(‘selector section one’);
var two = document.querySelectorAll(‘selector section two’);
var three = document.querySelectorAll(‘selector section three’);
var four = document.querySelectorAll(‘selector section four’);
var five = document.querySelectorAll(‘selector section five’);
var six = document.querySelectorAll(‘selector section six’);
var seven = document.querySelectorAll(‘selector section seven’);
var bigArr = [one,two,three,four,five,six,seven];
function populate(f){
for (var i = 0, len = bigArr.length; i < len; i++) {
var arr = [1,2,3,4,5,6,7];
Array.from(bigArr).forEach(function(e, i) {
e.textContent = arr[Math.round(Math.random()*(arr.length-1))];
});
};
}