原生js封装的一些jquery方法(详解)
用js封装一些常用的jquery方法 记录一下
hasClass:判断是否有class
function hasClass(ele, cls) { if (!ele || !cls) return false; if (ele.classList) { return ele.classList.contains(cls); } else { return ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)')); } }
addClass:增加class
function addClass(ele, cls) { if (ele.classList) { ele.classList.add(cls); } else { if (!hasClass(ele, cls)) ele.className += '' + cls; } }
removeClass:移除class
function removeClass(ele, cls) { if (ele.classList) { ele.classList.remove(cls); } else { ele.className = ele.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' '); } }
相关推荐
FlySky 2020-09-29
Phplayers 2020-09-05
oXiaoChong 2020-06-03
class Singleton: def __new__: # 关键在于这,每一次实例化的时候,我们都只会返回这同一个instance对象 if not hasattr: cls.instance =
lhxxhl 2020-05-16
laohyx 2020-04-06
pengkunstone 2020-02-22
codeAB 2020-01-19
逍遥友 2019-12-30
typhoonpython 2019-11-19
amazingbo 2019-06-30
pythonxuexi 2019-06-28
ruoyiqing 2016-10-13
cjb 2019-06-28
小方哥哥 2019-06-27
hualicc 2010-05-04
manbucy 2010-03-03
jibkfv 2019-06-20