標籤:jquery
1.通過使用onmouseover onmouseout方法2.變色使用background-color(css)屬性3.變色的標籤是td(tr只能使用事件,顏色樣式不起作用)第一種方法 使用樣式操作
<style>.tr_color{ background-color:#ffffff;}.tr_color_hover{ background-color:blanchedalmond;}</style><script type="text/javascript">function mover(obj){ $(obj).children("td").each(function(){ $(this).removeClass("tr_color"); $(this).addClass("tr_color_hover"); }) } function mback(obj){ $(obj).children("td").each(function(){ $(this).removeClass("tr_color_hover"); $(this).addClass("tr_color");})}</script> <tr onmouseover="mover(this)" onmouseout="mback(this)"> <td height="18" class="tr_color"></tr>
第二種方法 直接對背景色操作
<script type="text/javascript">function mover(obj){ $(obj).children("td").each(function(){ $(this).attr("bgColor","#eafcd5") }) } function mback(obj){ $(obj).children("td").each(function(){ $(this).attr("bgColor","#FFFFFF")})}</script> <tr onmouseover="mover(this)" onmouseout="mback(this)"> <td height="18"bgColor="#FFFFFF"></tr>
jQuery特效 隔行變色