JS 标签页切换
一
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>自适应宽度的标签导航</title>
<style>
body
{
font-size: 14px;
font-family: "宋体"
}
ol li { margin: 8px}
#con
{
font-size: 12px;
margin: 0px auto;
width: 600px
}
#tags
{
padding:0px;
margin: 0px 0px 0px 10px;
width: 400px;
height: 23px
}
#tags li
{
background: url(images/tagleft.gif) no-repeat left bottom;
float: left;
margin-right: 1px;
list-style-type:none;
height: 23px
}
#tags li a
{
padding-right: 10px;
padding-left: 10px;
background: url(images/tagright.gif) no-repeat right bottom;
float: left;
padding-bottom: 0px;
color: #999;
line-height: 23px;
padding-top: 0px;
height: 23px;
text-decoration:none
}
#tags li.emptyTag
{
background: none transparent scroll repeat 0% 0%;
width: 4px
}
#tags li.selectTag
{
background-position: left top;
margin-bottom: -2px;
position: relative;
height: 25px
}
#tags li.selectTag a
{
background-position: right top;
color: #000;
line-height: 25px;
height: 25px
}
#tagContent
{
padding: 1px;
border: #aecbd4 1px solid;
background-color: #fff
}
.tagContent
{
padding:10px;
display: none;
background: url(images/bg.gif) repeat-x;
width: 576px;
color: #474747;
height: 250px
}
#tagContent div.selectTag
{
display: block
}
</style>
</head>
<body>
<div id="con">
<ul id="tags">
<li class="selectTag"><a onMouseover="selectTag('tagContent0',this)" href="javascript:void(0)">标签一</a> </li>
<li><a onMouseover="selectTag('tagContent1',this)" href="javascript:void(0)">标签二</a> </li>
<li><a onMouseover="selectTag('tagContent2',this)" href="javascript:void(0)">自适应宽度的标签</a> </li>
<li><a onMouseover="selectTag('tagContent3',this)" href="javascript:void(0)">自适应宽度</a> </li>
</ul>
<div id="tagContent">
<div class="tagContent" id="tagContent0">第一个标签的内容</div>
<div class="tagContent selectTag" id="tagContent1">第二个标签的内容</div>
<div class="tagContent" id="tagContent2">第三个标签的内容</div>
<div class="tagContent" id="tagContent3">第四个标签的内容</div>
</div>
</div>
<script>
function selectTag(showContent,selfObj){
// 操作标签
var tag = document.getElementById("tags").getElementsByTagName("li");
var taglength = tag.length;
for(i=0; i<taglength; i++){
tag[i].className = "";
}
selfObj.parentNode.className = "selectTag";
// 操作内容
for(i=0; j=document.getElementById("tagContent"+i); i++){
j.style.display = "none";
}
document.getElementById(showContent).style.display = "block";
}
</script>
</html>
二
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
<style type="text/css">
#content {
width: 400px;
height: 200px;
}
#tab_bar {
width: 400px;
height: 20px;
float: left;
}
#tab_bar ul {
padding: 0px;
margin: 0px;
height: 20px;
text-align: center;
}
#tab_bar li {
list-style-type: none;
float: left;
width: 133.3px;
height: 20px;
background-color: gray;
}
.tab_css {
width: 400px;
height: 200px;
background-color: orange;
display: none;
float: left;
}
</style>
<script type="text/javascript">
var myclick = function(v) {
var llis = document.getElementsByTagName("li");
for(var i = 0; i < llis.length; i++) {
var lli = llis[i];
if(lli == document.getElementById("tab" + v)) {
lli.style.backgroundColor = "orange";
} else {
lli.style.backgroundColor = "gray";
}
}
var divs = document.getElementsByClassName("tab_css");
for(var i = 0; i < divs.length; i++) {
var divv = divs[i];
if(divv == document.getElementById("tab" + v + "_content")) {
divv.style.display = "block";
} else {
divv.style.display = "none";
}
}
}
</script>
</head>
<body>
<div id="content">
<div id="tab_bar">
<ul>
<li id="tab1" onclick="myclick(1)" >
tab1
</li>
<li id="tab2" onclick="myclick(2)">
tab2
</li>
<li id="tab3" onclick="myclick(3)">
tab3
</li>
</ul>
</div>
<div class="tab_css" id="tab1_content" style="display: block">
<div>页面一</div>
</div>
<div class="tab_css" id="tab2_content" style="display: none">
<div>页面二</div>
</div>
<div class="tab_css" id="tab3_content" style="display: none">
<div>页面三</div>
</div>
</div>
</body>
</html>
三
<!DOCTYPE HTML>
<html>
<head>
<style>
.content{
float:left;
}
.tab{
list-style: none;
float:left;
}
.tab-active{
border-bottom:none;
border-top-width: 2px;
height: 28px;
background:red;
color: #333333;
font-weight: bold;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<ul class="tab clearfix">
<li>标签1</li>
<li class="tab-active">标签2</li>
<li>标签3</li>
</ul>
<div class="content">
<div class="inner" style="display:none">
标签1内容
</div>
<div class="inner">
标签2内容
</div>
<div class="inner" style="display:none">
标签3内容
</div>
</div>
<script type="text/javascript">
var lists = $('.tab li');
var contents = $('.content .inner');
function bindEvent(){
lists.each(function(index_li, li){
$(this).on('click', function(event){
lists.removeClass('tab-active');
$(this).addClass('tab-active');
contents.each(function(index_content, content){
if(index_li === index_content){
$(this).show();
}else{
$(this).hide();
}
});
});
});
}
function init(){
bindEvent();
}
init();
</script>
</body>
</html>
JS 标签页切换的更多相关文章
- JS 标签页切换(复杂)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...
- JS实现标签页切换效果
本文实例为大家分享了JS标签页切换的具体代码,供大家参考,具体内容如下 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 ...
- 在Bootstrap开发中解决Tab标签页切换图表显示问题
在做响应式页面的时候,往往需要考虑更多尺寸设备的界面兼容性,一般不能写死像素,以便能够使得界面元素能够根据设备的不同进行动态调整,但往往有时候还是碰到一些问题,如Tab标签第一页面正常显示,但是切换其 ...
- JavaScript 实现 标签页 切换效果
JavaScript 实现 标签页 切换效果 版权声明:未经授权,严禁分享! 构建主体界面 HTML 代码 <h1>实现标签页的切换效果</h1> <ul id=&quo ...
- Android之ActionBar、Tabs、Fragment、ViewPager实现标签页切换并缓存页面
感觉 Android 到处都是坑,每个地方都要把人折腾半天. 今天来简单说说 Android之ActionBar.Tabs.Fragment.ViewPager 实现标签页切换并缓存页面 关于他们的介 ...
- web前端中实现多标签页切换的效果
在这里,实现多标签页效果的方法有两个,一个是基于DOM的,另一个是基于jquery的,此次我写的是一个对于一个电话套餐的不同,显示不同的标签页 方法一: 首先,我们要把页面的大体框架和样式写出来,ht ...
- python selenium-webdriver 标签页切换(十五)
测试过程中有时候会遇到点击某个按钮或者链接会弹出新的窗口,这时候我们的操作的页面还保持着最初打开页面,但是此时我们需要操作新打开的页面上的功能,这个时候我们需要切换一下标签页 . 其实页面的切换与fr ...
- vue单页面条件下添加类似浏览器的标签页切换功能
在用vue开发的时候,单页面应用程序,而又有标签页这种需求,各种方式实现不了, 从这个 到这个,然后再返回上面那个 因为每个标签页的route不一样,导致组件重新渲染的问题,怎么都不知道如何实现... ...
- html+css+js实现标签页切换
CSS部分: #Tab { margin:0 auto; width:640px; border:none; position:absolute; z-index:9; margin-left:320 ...
随机推荐
- 构建高性能高并发Java系统 .
转:http://blog.csdn.net/nengyu/article/details/7591854 场景这里指的高性能高并发服务器是一个有状态的服务,可以理解成web或者socket服务器,每 ...
- C++源文件的后缀名问题
VC里用cpp作后缀名, 在GCC里默认采用C.cc.cxx作为后缀名 .cpp, .h (VS file).cc, .h (GCC file) C中: 头文件后缀名: .h 源文件后缀名: .c ...
- python3 线程 threading.Thread GIL性能详解(2.3)
python3 线程 threading 最基础的线程的使用 import threading, time value = 0 lock = threading.Lock() def change(n ...
- 基于Netty的RPC架构学习笔记(五):netty线程模型源码分析(二)
文章目录 小技巧(如何看开源框架的源码) 源码解析 阅读源码技巧 打印查看 通过打断点调试 查看调用栈 小技巧(如何看开源框架的源码) 一断点 二打印 三看调用栈 四搜索 源码解析 //设置nioso ...
- 14-Ubuntu-文件和目录命令-查看目录内容-ls-1
1.终端使用技巧 (1)tab键自动补全 (2)按上/下光标键查看使用过的命令 (3)退出当前命令,Ctrl C (4)缩小--Ctrl - ;放大--Ctrl shift + 2.ls 命令--查看 ...
- sparkStreaming的transformation和action详解
根据Spark官方文档中的描述,在Spark Streaming应用中,一个DStream对象可以调用多种操作,主要分为以下几类 Transformations Window Operations J ...
- 2019-8-31-dotnet-判断程序当前使用管理员运行降低权使用普通权限运行
title author date CreateTime categories dotnet 判断程序当前使用管理员运行降低权使用普通权限运行 lindexi 2019-08-31 16:55:58 ...
- vba取局域网电脑共享文件夹下的Excel文件
Private Sub CommandButton1_Click() Dim xlapp1 As Excel.Application Dim xlbook1 As Excel.Workbo ...
- ES5给object扩展的一些静态方法
1. Object.create(prototype[, descriptors]) : 创建一个新的对象 1). 以指定对象为原型创建新的对象 2). 指定新的属性, 并对属性进行描述 value ...
- 帆软报表PC端实施报表心得体会
1.报表制作完成后,预览时自动显示查询内容,在控件处设置: 2.求一列数据的最小值(除去0),并对最小值字体加粗标绿,需要对对应单元格设置条件属性,并插入公式:C6 = min(greparray(C ...