📜  找到一个匹配模式的类名 - 任何代码示例

📅  最后修改于: 2022-03-11 14:57:11.184000             🧑  作者: Mango

代码示例1
var listClasses = function( pattern ){
    var allClassesTmp = {}, allClasses = []; 
    var rx = pattern ? (new RegExp(pattern)) : (new RegExp(".*"));

    $('*[class]').each( function(){ 
        var cn = this.className.split(/\s+/); 
        for(var i=cn.length;--i>-1;){ 
            if(rx.test(cn[i]))allClassesTmp[ cn[i] ] = 1 
        } 
    }); 
    for(var i in allClassesTmp)allClasses.push(i); 
    return allClasses;
}