<div class="codetitle"> <span><a style="CURSOR: pointer" data="34246" class="copybut" id="copybut34246" onclick="doCopy('code34246')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code34246"> <br><script type="text/javascript"> <BR>// 说明:添加、移除、检测 className <BR>function hasClass(element, className) { <BR>var reg = new RegExp('(\\s|^)'+className+'(\\s|$)'); <BR>return element.className.match(reg); <BR>} <BR>function addClass(element, className) { <BR>if (!this.hasClass(element, className)) <BR>{ <BR>element.className += " "+className; <BR>} <BR>} <BR>function removeClass(element, className) { <BR>if (hasClass(element, className)) { <BR>var reg = new RegExp('(\\s|^)'+className+'(\\s|$)'); <BR>element.className = element.className.replace(reg,' '); <BR>} <BR>} <BR></script> <br> </div>