JS+CSS實現的菜單

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
 </head>

 <body>
<style>
/* 先把這個 xmenu 的樣式放到css裏 */
.xmenu td{font-size:12px;font-family:verdana,arial;font-weight:bolder;color:#ffffff;border:1px solid #336699;background:#336699;filter:blendtrans(duration=0.5);cursor:hand;text-align:center;}
</style>
<script>
/*
http://lexrus.blueidea.com
這是把事件動作綁定到菜單上的函數
*/
function attachXMenu(objid){
var tds=document.getElementById(objid).getElementsByTagName('td');
for(var i=0;i<tds.length;i++){
with(tds[i]){
onmouseover=function(){
with(this){
filters[0].apply();
style.background='#66CCFF'; //這是鼠標移上去時的背景顏色
style.border='1px solid #ffffff'; //邊框
style.color='black'; //文字顏色
filters[0].play();
}
}
onmouseout=function(){
with(this){
filters[0].apply();
style.background='#336699'; //這是鼠標離開時的背景顏色
style.border='1px solid #336699'; //邊框
style.color='#ffffff'; //文字顏色
filters[0].play();
}
}
}
}
}
</script>
<!--菜單從這裏開始, 注意要把class設置成和css裏相同的, 還要爲它設一個id-->
<table class="xmenu" id="xmenu0" width="500" cellpadding="1" cellspacing="4" border="0" bgcolor="#336699" align="center">
<tr>
<td>My</td>
<td>Name</td>
<td>Is</td>
<td>yang</td>
<td>yongli</td>
<td>!!!</td>
</tr>
</table>
<script>attachXMenu("xmenu0"); //在上面這個table結束的地方執行事件動作的綁定, 這裏的這個xmenu0就是那個table的id</script>
<!--下面這個是豎排的-->
<br/>
<table class="xmenu" id="xmenu1" width="100" cellpadding="1" cellspacing="4" border="0" bgcolor="#336699" align="center">
<tr><td>My</td></tr>
<tr><td>Name</td></tr>
<tr><td>Is</td></tr>
<tr><td>yang</td></tr>
<tr><td>yongli</td></tr>
<tr><td>!!!</td></tr>
</table>
<script>attachXMenu("xmenu1");</script>
 </body>
</html>

效果:

http://p.blog.csdn.net/images/p_blog_csdn_net/yangyongli814/EntryImages/20080716/24.jpg

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章