标签:color turn class new dom 正则 bsp let hasclass
//使用正则判断DOM中是否已经存在该元素 export function hasClass(el, className) { let reg = new RegExp(‘(^|\\s)‘ + className + ‘(\\s|$)‘) return reg.test(el.className) }
//新增DOM元素 export function addClass(el, className) { if (hasClass(el, className)) { return } let newClass = el.className.split(‘ ‘) newClass.push(className) el.className = newClass.join(‘ ‘) }
标签:color turn class new dom 正则 bsp let hasclass
原文地址:https://www.cnblogs.com/marquess/p/12681838.html