Open VaJoy opened 7 years ago
let allClassName = ()=>{
let className = new Set();
let hasClassEl = document.querySelectorAll('[class]');
[].forEach.call(hasClassEl,(v,i)=>{
let classArr = v.getAttribute("class").split(' ');
classArr.map(name => className.add(name));
})
return [...className]
}
function getClass() {
let classes = [];
Array.from(document.querySelectorAll('[class]')).forEach(node=> {
classes = classes.concat(node.className.split(' '));
});
return Array.from(new Set(classes));
}
function getClassNames(){
var classes=document.querySelectorAll('[class]'),i;
var classNames=[];
for(i=0;i<classes.length;i++){
classNames=classNames.concat(classes[i].className.split(''));
}
var classArray=Array.from(new Set(classNames))
return classArray;
}
var classes = document.querySelectorAll('[class]');
classes = Array.prototype.slice.call(classes,0);
var classNames = [];
classes.forEach(function(v,k) {
classNames = classNames.concat(classes[k].className.split(''));
})
classNames = new Set(classNames);
有没有大神带带我学前端
[...new Set(Array.from(document.querySelectorAll('[class]')).map(({className: c}) => c).join(' ').split(' '))]
function allClassName() {
const classNames = [...document.querySelectorAll("[class]")].reduce(
(list, node) => [...list, ...node.classList.values()],
[]
);
return [...new Set(classNames)];
}
最终得到一个数组 实现方式多,但要尽量写的好看一点哦~