AddClass:function(value) {varclasses, Elem, cur, clazz, J, I= 0, Len= This. length, proceed=typeofValue = = = "string" &&value; if(jquery.isfunction (value)) {return This. each (function(j) {JQuery ( This). AddClass (Value.call ( ThisJ This. ClassName)); }); } if(Proceed) {//if the value passed in is not a string //The disjunction here's for better compressibility (see Removeclass) //if a false value is passed in, "". Match () //Core_rnotwhite is used to match non-whitespace characters, and has a G ID, the match returns the array successfully, the match does not return successfully []Classes = (Value | | ""). Match (core_rnotwhite) | | []; //Rclass =/[\t\r\n\f]/g for(; i < Len; i++) {Elem= This[i]; //if Elem is an element, CUR returns the true value, "" or "a B" //Replace tab character return line wrapCur = Elem.nodetype = = = 1 && (elem.classname? ( "+ Elem.classname +" "). Replace (Rclass," " ) : " " ); if(cur) {J= 0; //traversal, if not present in the original class, string concatenation while((Clazz = classes[j++]) ) { if(Cur.indexof ("" + Clazz + ") < 0) {cur+ = Clazz + ""; }} elem.classname= Jquery.trim (cur);//The last two sides go to space } } } return This; }
Removeclass is similar to the AddClass code.
JQuery addclass () Source code interpretation