鼠标点击span内文字改变其底色
有4个span内都有文字,现在我想点一个的时候,被点的那个背景色改变,点下一个的时候别的三个恢复本来的颜色
[解决办法]
<script language="JavaScript"> var curObj = null;var preColor;onload = function(){ var a = document.getElementById("pad").getElementsByTagName("span"); for(var i=0;i<a.length;i++){ a(i).onclick = (function(obj){ return function(){ if(curObj!=null) curObj.style.backgroundColor = preColor; preColor = obj.style.backgroundColor; obj.style.backgroundColor = "#CCC"; curObj = obj; } })(a(i)); }}</script><div id="pad"> <span> 111 </span> <span> 222 </span> <span> 333 </span> <span> 444 </span></div>