tab切换案例
做个简单的tab切换效果,分别于jquery和js操作
(1)jQuery操作
先看下效果:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
*{box-sizing:border-box;padding: 0;margin: 0}
ul{width: 100%;height: 50px;text-align: center;margin: 10px 0;}
ul li{list-style: none;height: 100%;width: 100px;
line-height: 50px;text-align: center;background-color: #9c8b8b;
margin: 0 6px;display: inline-block;cursor: pointer;}
section{width: 600px;height: 300px;border: 1px solid red;margin: 100px auto;}
#area{width: 400px;height: 200px;margin: 10px auto;border: 1px solid red;}
.child{width: 100%;height: 100%;float: left;display: none;text-align: center;line-height: 200px;font-size: 20px;color: black;}
.active{display: block}
#area .child:nth-child(1){
background-color: red;
}
#area .child:nth-child(2){
background-color: green;
}
#area .child:nth-child(3){
background-color: blue;
}
#area .child:nth-child(4){
background-color: yellow;
}
</style>
</head>
<body>
<section>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
<div id="area">
<div class="child active">
内容一
</div>
<div class="child">
内容二
</div>
<div class="child">
内容三
</div>
<div class="child">
内容四
</div>
</div>
</section>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<script>
$(function(){
$("ul li").on('click',function(){
var index = $(this).index();
$(".child").each(function() {
if (index == $(this).index()) {
$(this).siblings().removeClass('active');
$(this).addClass('active');
}
})
})
})
</script>
</body>
</html>
(2)js操作
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
*{
padding: 0;
margin: 0;
}
li{
list-style: none;
float:left;
}
#tabCon {
clear: both;
}
#tabCon div {
display:none;
}
#tabCon div.fdiv {
display:block;
}
</style>
</head>
<body>
<div id="tanContainer">
<div id="tab">
<ul>
<li>标题一</li>
<li>标题二</li>
<li>标题三</li>
<li>标题四</li>
</ul>
</div>
<div id="tabCon">
<div class="fdiv">内容一</div>
<div>内容二</div>
<div>内容三</div>
<div>内容四</div>
</div>
</div>
</body>
<script>
var tabs=document.getElementById("tab").getElementsByTagName("li");
var divs=document.getElementById("tabCon").getElementsByTagName("div");
for(var i=0;i<tabs.length;i++){
tabs[i].onclick=function(){
change(this);
}
}
function change(obj){
for(var i=0;i<tabs.length;i++){
console.log(tabs[i])
if(tabs[i]==obj){
divs[i].className="fdiv";
}else{
divs[i].className="";
}
}
}
</script>
</html>
.
tab切换案例的更多相关文章
- Angular——tab切换案例
基本介绍 angular框架下的tab切换,相比较于之前的纯js写的代码,有一个很大的特点就是以数据为驱动,基本上不用搜索dom元素就可以实现效果 基本使用 (1)导航部分使用的是的状态使用的是ng- ...
- JS---DOM---tab切换案例实现---排他
tab切换案例实现 <!DOCTYPE html> <html> <head lang="en"> <meta charset=" ...
- WPF案例(-)模拟Windows7 Win+Tab切换
原文:WPF案例(-)模拟Windows7 Win+Tab切换 一个使用Wpf模拟Windows7 Win+Tab页面切换的小程序,使用快捷键Ctrl+Down或Ctrl+Up在示例程序各个页面元素之 ...
- Android Studio精彩案例(二)《仿微信动态点击底部tab切换Fragment》
转载本专栏文章,请注明出处,尊重原创 .文章博客地址:道龙的博客 现在很多的App要么顶部带有tab,要么就底部带有tab.用户通过点击tab从而切换不同的页面(大部分情况时去切换fragment). ...
- 案例(拖拽对话框、高清放大镜、自制滚动条、元素的隐藏方式、表格隔行变色、tab切换效果、字符串拼接、刷新评论)
一.拖拽对话框 <style> .of{ width: 500px; } #link,#close{ text-decoration: none; margin: 0 10px; font ...
- Js 实现tab切换效果
今天商城系统的后台要添加一个Tab切换的效果,一开始没有思路想要自己去实践这个效果 从网上找jquery 已经有了很好看的案例,实现之后我来学习下思路是如何完成的
- bootstrap tab切换如何让鼠标移动自动切换内容
bootstrap集成了很多功能,比如nav-tabs组件,可以将相似的内容集中在一个区块中展示.bootstrap tab切换默认是要点击才会切换的,如何实现鼠标移动就自动切换呢?如下图所示,光标移 ...
- 原生JS实现tab切换--web前端开发
tab切换非常常见,应用非常广泛,比较实用,一般来说是一个网站必不可少的一个效果.例如:https://123.sogou.com/中的一个tab部分: 1.案例源代码 <!DOCTYPE ht ...
- echarts tab 切换问题整理
一.bootstrap tabs 解决方案 方式一 tab切换echarts无法正常显示 https://blog.csdn.net/cjs68/article/details/78072382 ta ...
随机推荐
- configure: error: mysql configure failed. Please check config.log for more information.
为php添加mysql模块时报错 configure: error: mysql configure failed. Please check config.log for more informat ...
- "未能载入文件或程序集“XXX”或它的某一个依赖项。系统找不到指定的文件"的解决方式
今天在写反射调用的时候失败了,经过调试和分析,终于攻克了,以下我就详细说明. 一,报错的现象 未能载入文件或程序集"DalSQL"或它的某一个依赖项.系统找不到指定的文件. 说明: ...
- poj 3020 Antenna Placement(二分无向图 匈牙利)
Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6438 Accepted: 3176 ...
- Java 实现的断点下载
该断点下载可应用于浏览器或者迅雷等下载工具的下载,实现方式有多种多样的,本文仅仅研究了单线程的下载.迅雷等下载工具会自己主动将下载资源分块并记录每块的起始位置,然后依据系统性能.起多线程下载. 1. ...
- Getting console.log output with Selenium Python API bindings
持久化存储 Getting console.log output from Chrome with Selenium Python API bindings - Stack Overflow http ...
- MapReduce的矩阵相乘
一.单个mapreduce的实现 转自:http://blog.sina.com.cn/s/blog_62186b460101ai1x.html 王斌_ICTIR老师的<大数据:互联网大规模数据 ...
- 深入理解7816(2)---关于ATR【转】
本文转载自:http://blog.sina.com.cn/s/blog_4df8400a0102vcrk.html 深入理解7816(2)---关于ATR 智能卡(此处主要指接触式CPU卡)本身始终 ...
- 数组和字符串长度length
数组.length 字符串.length() list list.size();map map.size();set set.size();1 java中的length属性是针对数组说的,比如说你声明 ...
- P3469 [POI2008]BLO-Blockade tarjan
好久没发博客了啊!自我反省1s...今天再捡起来. 这个题是一道有一点特殊的tarjan,用tarjan维护子树大小,然后判断是否有边多次连接,(就是非树边),然后就进行乘法计算就行了. 具体在代码里 ...
- 如何用css约束一个层不可见
两种方式: 方式一:设置属性值为none不可见:display:none 这个属性改变了一个元素的显示效果.之前我有提到一点,假如元素使用了none值,那么元素直接干净利落的消失不见.你在右键审查元素 ...