码迷,mamicode.com
首页 > Web开发 > 详细

jQuery写选项卡

时间:2017-02-23 11:20:44      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:第一个   pointer   java   cti   选项   hover   状态   splay   on()   

<!DOCTYPE html>

<htmllang="en">

<head>

<metacharset="UTF-8"><title>choseCart</title>

<script src="https://cdn.bootcss.com/jquery/1.8.3/jquery.js"></script>

<styletype="text/css">

*{margin: 0;padding: 0;}

li{list-style: none;}

#menu {height: 30px;}

#menu li{float: left;background: #999;color: #fff;cursor: pointer;border:2px solid #666;}

#menu .active{border-right-color: #666;border-left-color: #666;border-top-color: blue;border-bottom-color: #fff}

#pannel div:nth-of-type(1){background: green;width: 335px;height: 200px;}

#pannel div:nth-of-type(2){background: blue;width: 335px;height: 200px;}

#pannel div:nth-of-type(3){background: black;width: 335px;height: 200px;}

#pannel div:nth-of-type(4){background: red;width: 335px;height: 200px;}

#pannel div{display: none;}

#pannel .active{display: block;}

</style><scripttype="text/javascript">

$(function(){

let oLi=$(‘#menu li‘);

/*oLi.bind(‘click‘,function() {

let iIndex=$(this).index();oLi.removeClass(‘active‘).eq(iIndex).addClass(‘active‘);

$(‘#pannel div‘).removeClass(‘active‘).eq(iIndex).addClass(‘active‘);

});*/

oLi.hover(function(){

let iIndex=$(this).index();

oLi.removeClass(‘active‘).eq(iIndex).addClass(‘active‘);

$(‘#pannel div‘).removeClass(‘active‘).eq(iIndex).addClass(‘active‘);

})

})

</script>

</head>

<body>

<divid="box">

<ulid="menu">

<liclass="active">第一个按钮</li>

<li>第二个按钮</li>

<li>第三个按钮</li>

<li>第四个按钮</li>

</ul>

<divid="pannel">

<divclass="active"></div>

<div></div>

<div></div>

<div></div>

</div></div>

</body>

</html>

回来再总结下思路吧:

1:CSS布局要点:默认按钮和内容区域第一个为active状态,

2:写jQuery时通过addClass()/removeClass()来改变卡片的状态;

jQuery写选项卡

标签:第一个   pointer   java   cti   选项   hover   状态   splay   on()   

原文地址:http://www.cnblogs.com/tiny-jiao/p/6432227.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!