jQuery - 不是纯JavaScript

alb*_*vee 5 javascript jquery

我怎么能写下面的jQuery - 不...

$(".hover").not(".selected");
Run Code Online (Sandbox Code Playgroud)

...在纯JavaScript中?

Ali*_*aru 7

allItems = document.getElementsByTagName('*');
goodItems = [];
for(i=0;i<allItems.length;i++){
    if(
        allItems[i].className && 
        (' '+allItems[i].className.replace(/\s+/g, ' ')+' ').indexOf(' '+'hover'+' ') != -1 && 
        (' '+allItems[i].className.replace(/\s+/g, ' ')+' ').indexOf(' '+'selected'+' ') == -1
    )
        goodItems.push(allItems[i]);
}
Run Code Online (Sandbox Code Playgroud)

如果您经常需要这些类选择,您应该考虑将它们保存为函数,甚至复制一些jQuery行为,以便能够执行类似的操作 $(".hover").not(".selected");