基于jquery的9行js轻松实现tab控件示例
代码如下:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script> <script type="text/javascript"> /** * 考虑到tab和pane有可能被动态的添加和删除, * 所以每次都废点时间去查找先前被激活的tab */ var tab = function(tabId,activeId){ $("#"+tabId).delegate("li:not(#"+activeId+")","click",function(){ $("#"+$("#"+activeId).attr("tar")).css("display","none"); $("#"+activeId).removeAttr("id"); $(this).attr("id",activeId); $("#"+$(this).attr("tar")).css("display","block"); }); }; </script> </head> <style> li{ border:1px solid #b5e2f3; border-bottom:0px; float:left; width:100px; height:25px; margin:0 7px; background:#F1FEF3; padding:9px 0 0 0; text-align:center; color:#33a3dc; cursor:pointer; } ul{ width:800; height:36px; border-bottom:1px solid #b5e2f3; } #selected{ background:#FFF!important; border-bottom:2px solid #FFF!important; } ul{margin:-1px;} #cate1,#cate2, #cate3, #cate4, #cate5{ clear:both; height:300px; background:#FFFFFF; width:800px; height:100px; padding:25px; border:1px solid #b5e2f3; } </style> <body> <div id="tab"> <ul> <li tar="cate1" id="selected">1</li> <li tar="cate2">2</li> <li tar="cate3">3</li> <li tar="cate4">4</li> </ul> </div> <div> <div id="cate1" style="display:block;"> 1 </div> <div id="cate2" style="display:none;"> 2 </div> <div id="cate3" style="display:none;"> 3 </div> <div id="cate4" style="display:none;"> 4 </div> </div> </body> <script> tab("tab","selected"); </script> </html>
相关推荐
88274956 2020-11-03
runner 2020-09-01
梦的天空 2020-08-25
移动开发与培训 2020-08-16
ReunionIsland 2020-08-16
lyqdanang 2020-08-16
MyNameIsXiaoLai 2020-07-08
星辰的笔记 2020-07-04
csstpeixun 2020-06-28
letheashura 2020-06-26
liaoxuewu 2020-06-26
sunzhihaofuture 2020-06-21
FEvivi 2020-06-16
坚持着执着 2020-06-16
waterv 2020-06-14
xiaoge00 2020-06-14
firejq 2020-06-14
firstboy0 2020-06-14
e度空间 2020-06-12
zhongweinan 2020-06-10