//判断有无 function hasClass(ele, cls) { return ele.className.match(new RegExp("(\\s|^)" + cls + "(\\s|$)")); } //添加 function addClass(ele, cls) { if (!this.hasClass(ele, cls)) ele.className += " " + cls; } //删除 function removeClass(ele, cls) { if (hasClass(ele, cls)) { let reg = new RegExp("(\\s|^)" + cls + "(\\s|$)"); ele.className = ele.className.replace(reg, " "); } }
js操作class
猜你喜欢
转载自www.cnblogs.com/chao202426/p/11528212.html
今日推荐
周排行