首页 > 代码库 > hasClass addClass removeClass

hasClass addClass removeClass

//函数有classfunction hasClass(ele,cls){return -1<(" "+ele.className+" ").indexOf(" "+cls+" ")}//添加classfunction addClass(ele,cls){if((" "+ele.className+" ").indexOf(" "+cls+" ")==-1){ele.className+=" "+cls;}else{return}}//删除classfunction removeClass(ele,cls){if((" "+ele.className+" ").indexOf(" "+cls+" ")>-1){var reg = new RegExp(‘(\\s|^)‘+cls+‘(\\s|$)‘);ele.className=ele.className.replace(reg,‘ ‘) //注意替换为空格}}

hasClass addClass removeClass