日期:2014-05-16 浏览次数:20363 次
<script type="text/javascript">
window.onload = function(){
var table = document.getElementById('table');
var links = table.getElementsByTagName('a');
for(var i = 0 ; i < links.length ; ++i){
links[i].onmouseover = function(){
this.style.color = '#FFFFFF';
getParent(this).style.backgroundColor='#FF0000';
}
links[i].onmouseout = function(){
this.style.color = '';
getParent(this).style.backgroundColor='';
}
}
}
function getParent(note){
var parent = note.parentNode;
if(parent.nodeType==1){
return parent;
}else{
return getParent(parent);
}
}
</script>
<table id="table" width="250" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#006633">
<td><a href="javascript:void(0);">菜单1</a></td>
<td><a href="javascript:void(0);">菜单2</a></td>
<td><a href="javascript:void(0);">菜单3</a></td>
<td><a href="javascript:void(0);">菜单4</a></td>
<td><a href="javascript:void(0);">菜单5</a></td>
</tr>
</table>
<style type="text/css">
.a{background-color:red;color:#FFFFFF}
.b{background-color:red;}
.c{color:#FFFFFF}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$("table tr td").hover(function(){
if(!$(this).hasClass("b")){
$(this).addClass("a");
}
},function(){
if(!$(this).hasCla