. 代碼如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="js/jquery-1.7.min.js"></script>
<head>
<title>選項卡插件制作</title>
<style type="text/css">
*{margin: 0;padding: 0}
.tab{width: 350px;margin: 100px auto;}
.tabnav li{ list-style:none;cursor:pointer;float: left;width: 80px;border: 1px solid #ccc;border-radius: 5px;margin-right: 5px; height:24px;line-height: 24px;text-align: center;}
.tabnav li.cur{background:#daa520;}
.tabcontent{display: none;padding: 20px;}
.tabcon{border: 1px #708090 solid;background: #ffc0cb;height: 300px;clear: both;}
</style>
</head>
<script>
(function($){
$.fn.extend({
myTab:function(options){
var confings={
tabNav:'',//tab導航名稱
tabTag:'',//tab導航標簽
tabCon:'',//tab內容名稱
conTag:'',//tab內容標簽和其他的類名
method: 'click'//鼠標事件狀態
};//默認設置
options= $.extend(confings,options);
var that=$(this);
var tagnav=$(confings.tabNav);
var tabLi=tagnav.find(confings.tabTag);
var tabcon=$(confings.tabCon);
var tabUl=tabcon.find(confings.conTag);
var timoutid=null;
tabLi.each(function(ind){
$(this).bind(options.method,function(){
var liNode = $(this);
timoutid = setTimeout(function(){ //鼠標不小心劃過的延遲時間
tabUl.hide();
tabLi.removeClass("cur");
tabUl.eq(ind).show();
liNode.addClass("cur");
},300);
}).mouseout(function(){
clearTimeout(timoutid);
});
})
return this;
}
})
})(jQuery);
$(function(){
$("#testtab5").myTab({
tabNav:"#tabtag5",tabTag:"li",tabCon:"#tabcon5",conTag:".tabcontent",method:"mouseover"
});
$("#testtab").myTab({
tabNav:"#tabtag",tabTag:"li",tabCon:"#tabcon",conTag:".tabcontent"
});
})
</script>
<body>
<div class="tab" id="testtab5">
<div class="tabnav" id="tabtag5">
<ul>
<li class="cur">菜單一</li>
<li>菜單二</li>
<li>菜單三</li>
</ul>
</div>
<div class="tabcon" id="tabcon5">
<div class="tabcontent" style="display: block;">內容一</div>
<div class="tabcontent">內容二</div>
<div class="tabcontent">內容三</div>
</div>
<div style="clear: both;margin-top: 60px;">
<div class="tab" id="testtab">
<div class="tabnav" id="tabtag">
<ul>
<li class="cur">菜單一</li>
<li>菜單二</li>
<li>菜單三</li>
</ul>
</div>
<div class="tabcon" id="tabcon">
<div class="tabcontent" style="display: block;">內容一</div>
<div class="tabcontent">內容二</div>
<div class="tabcontent">內容三</div>
</div>
</div>
</div>
</div>
</body>
</html>