日期:2014-05-17 浏览次数:20599 次
<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>