版权声明:内容多为自言自语,请自行判断有无价值。 https://blog.csdn.net/weixin_41702247/article/details/83054849
var appendDiv=function(count,cb){
for(let i=0;i<count;i++){
let div=document.createElement('div'); //创建
div.innerHTML=`This is the ${i} div`; //设置内容
document.body.appendChild(div); //插入页面
if(typeof cb==='function'){ //判断第二参数是否为函数,是的话就把div作为参数传进去并执行
cb(div);
}
}
}
appendDiv(3,node=>node.style.color='#666');