效果示範:具體代碼:<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"><html lang="us-en"><head><title>css選項卡(html組件)</title><link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /><meta http-equiv="content-type" content="text/html; charset=gb2312" /><meta name="keywords" content=" "/><meta name="description" content="" /><style type="text/css">div.card div{ background-color:#FF8000; float:left; padding:1px; padding-bottom:0; clear:both; width:405px;}div.card a{ color:black; font-size:14px; text-decoration:none; float:left; width:100px; text-align:center; background-color:white; margin-right:1px;}div.card div.home a.home{ font:normal normal bold 14px/1.5 宋體;}div.card div.international a.international { font:normal normal bold 14px/1.5 宋體;}div.card div.sport a.sport{ font:normal normal bold 14px/1.5 宋體;}div.card div.finance a.finance{ font:normal normal bold 14px/1.5 宋體;}div.card div.content{ background-color:white; border:1px solid #ff8000; height:100px;}</style><script type="text/javascript">var shq={}// 首先建立一個空的對象沒有任何元素shq.cmenu=function(e)// 給Null 物件添加一個方法{var e=window.event?window.event.srcElement:e.target;//三元運算子相當於if else 如果window有event屬性則變數e的值為window.event.srcElement或則為e.target;這個因該是瀏覽器event事件相容問題Firefoxevent事件為局部變數ie為全域變數 其它是進行了瀏覽器測試 if(/a/i.test(e.tagName)){// 正則匹配e.tagName是否為a不區分大小寫如果為真就執行裡面的代碼塊 e.parentNode.className=e.className; // e的父節點的class屬性等於e的class屬性值 e.parentNode.nextSibling.innerHTML=e.innerHTML; // e的父節點的class屬性等於e的class屬性值innerHTML(html代碼) = e的innerHTML代碼 e.parentNode.nextSibling.style.cssText='border-top:none'; // e的父節點的下一個子節點的css真接修改為border-top:none; e.blur();// 失去滑鼠焦點 }}</script></head><body><div class="card"><div onclick="shq.cmenu(event)"><a href="#" class="home">國內</a><a href="#" class="international">國際</a><a href="#" class="sport">體育</a><a href="#" class="finance">財經</a></div><div class="content"></div></div> <div class="card"><div onclick="shq.cmenu(event)"><a href="#" class="home">國內</a><a href="#" class="international">國際</a><a href="#" class="sport">體育</a><a href="#" class="finance">財經</a></div><div class="content"></div></div> <div class="card"><div onclick="shq.cmenu(event)"><a href="#" class="home">國內</a><a href="#" class="international">國際</a><a href="#" class="sport">體育</a><a href="#" class="finance">財經</a></div><div class="content"></div></div></body></html>