<div id="colors" class="pre spec">
<c:forEach items="${colors}" var="color">
<a οnclick="colorToRed(this)" href="javascript:void(0)" title="西瓜红" class="changToRed"><img width="25" height="25" data-img="1" src="/res/img/pic/ppp00.jpg" alt="西瓜红 "><i>${color.name }</i></a>
</c:forEach>
</div>
遍历id为colors里面的所有标签为a的标签
<pre name="code" class="javascript">function colorToRed(target){
//先清理
$("#colors a").each(function(){
$(this).attr("class","changToWhite");
});
$(target).attr("class","changToRed");
}