<div class="codetitle"> <span><a style="CURSOR: pointer" data="44302" class="copybut" id="copybut44302" onclick="doCopy('code44302')"><u>复制代码</u></a></span>代码如下:</div> <div class="codebody" id="code44302"> <br> <br><头> <br><meta http-equiv="Content-Type" content="text/html; charset=utf-8">> <br><标题></标题> <br><script type=text/javascript src="alabel.js"></script> <br> <br>.curr{背景:蓝色;显示:内联;} <br></style> <br><br></头> <br><身体> <br><div class="clMenu"> <br><span><a href="#">1</a></span> <br></div> <br><br></body> <br></html> <br> </div> <br>在alabel.js中: <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="36016" class="copybut" id="copybut36016" onclick="doCopy('code36016')"><u>复制代码</u></a></span>代码如下:</div> <div class="codebody" id="code36016"> <br>window.onload = function () <br>{ <br>var aspan = document.getElementsByTagName("span"); <br>var i = 0; <br>for (i = 0; i { <br>aspan[i].onclick = function () <br>{ <br>for (i = 0; i <br>for (i = 0; i <br>) ; aspan.length; i ) aspan[i].className = ""; <br>this.className = "curr"; <br>}; <br>} </div>}; <br><br> <br>这样就可以实现在点击标签的时候给其添加红色的背景。 注意:curr的属性中显示不能是block,否则添加的背景是一个整体行。