jquery源代码分析之dom操作:hasClass

      hasClass(className):判断匹配的元素是否含某个类

      @param (string) className;

      @return (boolean)

 

 1        var className = " " + selector + " ",
 2             i = 0,
 3             l = this.length;
 4         for ( ; i < l; i++ ) {
 5             /*
 6                 1.最关键是使用到indexOf
 7             */
 8             if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) > -1 ) {
 9                 return true;
10             }
11         }
12 
13         return false;
posted on 2012-06-26 14:55  musickog  阅读(158)  评论(0编辑  收藏  举报