JQuery+Ajax Tab标签页

工程结构:

011050_xdaI_2368115.png

页面代码:

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Tab-独行冰海</title>
<style>
* {
	margin: 0;
	padding: 0;
}

.tab {
	width: 375px;
	margin: 25px auto;
}

.tabTit li {
	float: left;
	width: 123px;
	height: 38px;
	border: 1px solid #00f;
	text-align: center;
	background: #ccf;
	line-height: 38px;
	list-style: none;
}

.tabTit li:hover {
	background: #aaf;
	cursor: hand;
	cursor: pointer;
}

.tabTit .select {
	background: #99f;
}

.tabCon {
	width: 373px;
	height: 400px;
	border: 1px solid #00f;
	border-top: none;
}

.tabCon h1 {
	font-size: 24px;
}

.tabCon p {
	text-indent: 2em;
}
</style>
</head>
<body>
	<div id='tab' class='tab'>
		<ul id='tabTit' class='tabTit'>
			<li class='select'>标题一</li>
			<li>标题二</li>
			<li>标题三</li>
		</ul>
		<div class='tabCon'>
			<h1 id='tabConTit'>独行冰海的博客</h1>
			<p id='tabInf'>独行冰海的博客创建于2006年8月,那时申请博客似乎是在邮箱申请的时候误点误撞的。到了2009年才开始动手写博客。渐渐发现博客的重要作用。</p>
		</div>
	</div>
</body>
<script type="text/javascript" src="js/jquery-1.12.0.min.js"></script>   
<script>
	$('#tabTit li').click(function() {
		var index = $(this).index();
		$.getJSON('tab.json', function(data) {
			$('#tabConTit').html(data[index].tit);
			$('#tabInf').html(data[index].con);
		})
		$(this).addClass('select').siblings().removeClass('select');
	});
</script>
</html>


Json:

[
    {
        "tit" : "独行冰海的博客",
        "con" : "独行冰海的博客创建于2006年8月,那时申请博客似乎是在邮箱申请的时候误点误撞的。到了2009年才开始动手写博客。渐渐发现博客的重要作用。"
    },
    {
        "tit" : "独行冰海的微博",
        "con" : "独行冰海的微博创建时间有些晚了,已经是2012年的事情了,或许是在大学中过于封闭的生活所至,对于微博,一直没有很高的关注度,但不得不说,微博是专业信息汇集的一个好地方。"
    },
    {
        "tit" : "独行冰海的教育之路",
        "con" : "独行冰海在2011年踏上了教育的旅途,而今已经三年了,三年来,一直遵循着自己的原则:从不以从不以“地位”、“权力”为目标,只为了自己心底的梦、珍重的事、守护的情而奋斗。"        
    }
]


转载于:https://my.oschina.net/u/2368115/blog/609297

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值