jQuery tabs 小插件

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;" charset="utf-8" />
<title></title>
<style type="text/css">
*{ margin: 0; padding: 0;}
ul,li{ list-style-type: none}
.myFirstTab{ width: 600px; height: 630px;}

.tabList{ width: 600px; height: 30px;}

.liUnSelect{ width:200px; height: 30px; float: left; background: #ccc; text-align: center;; line-height: 30px; color: #666}
.liSelect{width:200px; height: 30px; float: left; background: #999; text-align: center;; line-height: 30px; color: #666;}

.myFirstTab div{ width: 600px; height: 600px; background: #c0c0c0}
</style>
<script type="text/javascript" src="jquery-1.8.3.min.js"></script>
<script type="text/javascript">
;(function($){
$.fn.tabs = function(options){
var defaults = {switchingMode:‘click‘};
var settings = $.extend({},defaults,options);
var obj = $(this);
var clickIndex = 0;

obj.addClass(‘myFirstTab‘);
$(‘ul‘,obj).addClass(‘tabList‘);
$(‘ul li:first‘,obj).addClass(‘liSelect‘);
$(‘ul li‘,obj).not(‘:first‘).addClass(‘liUnSelect‘);
$(‘div‘,obj).not(‘:first‘).hide();
$(‘ul li‘,obj).bind(settings.switchingMode,function(){
$(this).addClass(‘liSelect‘).siblings(‘li‘).addClass(‘liUnSelect‘).removeClass(‘liSelect‘);
var i = $(this).index();
$(‘div‘,obj).eq(i).show().siblings(‘div‘).hide();
});
}

})(jQuery);

$(function(){
$(‘#myFirstTab‘).tabs();
})
</script>
</head>
<body>
<div id="myFirstTab">
<ul>
<li>tab1</li>
<li>tab2</li>
<li>tab3</li>
</ul>
<div>1</div>
<div>2</div>
<div>3</div>
</div>
</body>
</html>

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。