<script type="text/javascript">
// 说明:添加、移除、检测 className
function hasClass(element, className) {
var reg = new RegExp('(\\s|^)'+className+'(\\s|$)');
return element.className.match(reg);
}
function addClass(element, className) {
if (!this.hasClass(element, className))
{
element.className += " "+className;
}
}
function removeClass(element, className) {
if (hasClass(element, className)) {
var reg = new RegExp('(\\s|^)'+className+'(\\s|$)');
element.className = element.className.replace(reg,' ');
}
}
</script>
js 添加、移除、检测 className
最新推荐文章于 2024-01-04 21:02:47 发布