61,115
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>H5+jquery点击切换</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="js/jquery-2.1.4.min.js" ></script>
<script type="text/javascript" src="js/jquery.mobile-1.4.5.min.js" ></script>
<script type="text/javascript" src="js/tab.js"></script>
</head>
<body>
<div data-role="page">
<div data-role = "content-floud">
<div style="font-family: '微软雅黑';">
<ul id="hear">
<li class="action" style="border-bottom: 2px solid red;height: 43px;"><a href="javascript:void(0)">未使用<span style="color: red;">(0)</span></a></li>
<li><a href="javascript:void(0)" >已使用<span style="color: red;">(8)</span></a></li>
<li><a href="javascript:void(0)" >已过期<span style="color: red;">(2)</span></a></li>
</ul>
<ul id="contentop">
<li class="action">
weishiyong
</li>
<li>
yishiyong
</li>
<li>
yiguoqi
</li>
</ul>
</div>
</div>
</div>
</body>
</html>
样式
*{text-decoration: none;margin: 0;padding: 0;list-style: none;}
#hear{width: 100%;height: 44px;line-height: 45px;border-bottom: 1px solid #cccccc;}
#hear a{font-weight: normal;color: black;}
#hear li{text-align: center;float: left;height: 45px;}
#hear li:nth-of-type(1){width: 33%;float: left;}
#hear li:nth-of-type(2){width: 33%;float: left;}
#hear li:nth-of-type(3){width: 34%;float: right;}
#contentop li{ width: 90%; display: none;text-align: center;margin: 0 auto;margin-top: 12px;}
#contentop .action{ display: block;}
#contentop .usl{width: 100%;height: 110px;background:wheat;border: 1px solid #cccccc;margin-bottom: 10px;text-shadow: none;}
#contentop .alo{width: 100%;height: 110px;background: white;border: 1px solid #cccccc;margin-bottom: 10px;text-shadow: none;}
#contentop span{font-size: 1.3em;color: #47B0D7;}
#contentop .sty1{margin-top: 18px;}
#contentop .sty2{margin-top: 13px;}
#contentop .sty3{margin-top: 13px;}
#contentop .sty4{text-align: right;font-size: 0.8em;margin-top: -20px;}
#contentop .Buy{font-size: 0.8em;margin-top: 2px;}
#contentop .Buy div:nth-of-type(1){text-align: left;padding-left: 15px;}
#contentop .Buy div:nth-of-type(2){float: right;}
#contentop .cllio {background:url(../img/20010.png)repeat-x;width: 93%;height:8px;margin: 0 auto;margin-top: 5px;}
jQuery引用
$(function(){
$("#hear li").click(function(){
$(this).css({
borderBottom: "2px solid red",
height:"43px"
}).siblings().css({
borderBottom: "none",
height:"45px"
});
});
$("#hear li").click(function(){
$(this).addClass("action").siblings().removeClass("action");
var index = $(this).index();
$("#contentop li").eq(index).css("display","block").siblings().css("display","none");
});
});
然后自己下载一个jQuery文件
<style>
body { font : 14px/1.5 "Microsoft Yahei"; }
ul { margin : 0; }
a { color : #428bca; text-decoration : none; background-color : transparent; }
.nav-tabs { border-bottom : 1px solid #dddddd; padding-left : 0; margin-bottom : 0; list-style : none; }
.nav-tabs:before { display : table; content : " "; }
.nav-tabs:after { display : table; content : " "; clear : both; }
.nav-tabs > li { position : relative; display : block; float : left; margin-bottom : -1px; }
.nav-tabs > li > a { position : relative; display : block; line-height : 1.42857143;
border: 1px solid transparent; border-radius : 4px 4px 0 0; padding : 10px 15px; margin-right : 2px; }
.nav-tabs > li.active > a,
.nav-tabs > li.active > a:hover,
.nav-tabs > li.active > a:focus { color : #555555; cursor : default; background-color : #ffffff;
border: 1px solid #dddddd; border-bottom-color : transparent; }
.tab-content { border : solid 1px #dddddd; border-top : none 0; min-height : 300px; padding : 20px; }
.tab-content > .tab-pane { display : none; visibility : hidden; }
.tab-content > .active { display : block; visibility : visible; }
</style>
<script>
$( document ).ready( function ( $ ) {
// 点击页签
$( ".nav-tabs" ).find( "li" ).on( "click", function () {
var $this,
$targetPanel
;
$this = $( this );
$targetPanel = $( $this.find( "a" ).attr( "href" ) );
// 1. 切换页签active
$this.addClass( "active" )
.siblings().removeClass( "active" );
// 2. 切换面板active
$targetPanel.addClass( "active" )
.siblings().removeClass( "active" );
} );
} );
</script>
<div class="container">
<!-- Nav tabs:active状态的会高亮显示 -->
<ul class="nav-tabs">
<li class="active"><a href="#course-list">课程列表</a></li>
<li><a href="#course-answer">课程回答</a></li>
</ul>
<!-- Tab panes:active状态的会显示,其他的会隐藏 -->
<div class="tab-content">
<div class="tab-pane active" id="course-list">
<ul>
<li><a href="#">web学习</a></li>
<li><a href="#">HTML入门</a></li>
</ul>
</div>
<div class="tab-pane" id="course-answer">
<ul>
<li><a href="#">web学习解答</a></li>
<li><a href="#">HTML入门解答</a></li>
</ul>
</div>
</div>
</div>