javascript實(shí)現(xiàn)不同顏色Tab標(biāo)簽切換效果
本文實(shí)例為大家分享了javascript不同顏色Tab標(biāo)簽切換效果的實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下

具體代碼:
<html>
<head>
<title>不同顏色選項(xiàng)卡</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
body {
font: 12px/20px 'microsoft yahei', 'arial';
word-break: break-all;
word-wrap: break-word;
}
.clearfix:after {
content: '.';
display: block;
clear: both;
height: 0;
visibility: hidden;
}
.clearfix {
display: inline-block;
}
* html .clearfix {
height: 1%;
}
.clearfix {
display: block;
}
#wrap {
width: 320px;
margin: 2em auto;
}
.card_List {
height: 30px;
border-bottom: 1px solid #f00;
position: relative;
}
.card_List li {
float: left;
width: 68px;
text-align: center;
height: 30px;
line-height: 30px;
margin: 0 5px;
display: inline;
border-top-left-radius: 6px;
border-top-right-radius: 6px;
}
.card_List li.current {
height: 34px;
line-height: 34px;
margin-top: -4px;
border: 1px solid #F00;
background: #FF9494;
border-bottom: none;
color: #fff;
}
#oLi li:nth-child(1){
background: #FF9494;
}
#oLi li:nth-child(2){
background: #8CFE8C;
}
#oLi li:nth-child(3){
background: #6969FB;
}
#oLi li:nth-child(4){
background: #FFE26F;
}
.card_content div {
display: none;
height: 100px;
text-align: center;
color: #000;
}
.card_content div:first-child {
background: #fff;
}
</style>
<script type="text/javascript">
window.onload = function () {
var colorArr = {
0:"#f00",
1:"#0f0",
2:"#00f",
3:"#FC0"
};
var bgColorArr = {
0:"#fff",
1:"#fff",
2:"#fff",
3:"#fff",
}
var oL = document.getElementById("oLi");
var oLi = oL.getElementsByTagName("li");
var oUl = document.getElementById("oUl").getElementsByTagName("div");
for ( var i=0 ; i<oLi.length ; i++ ){
oLi[i].index = i;
oLi[i].onclick = function () {
for ( var j = 0 ; j < oLi.length ; j++ ){
oLi[j].className = "";
oLi[j].style.border = "none";
}
this.className = "current";
this.style.border = "1px solid " + colorArr[this.index];
this.style.borderBottom = "none";
oL.style.borderBottom = "1px solid " + colorArr[this.index];
for ( var j=0 ; j < oUl.length ; j++ ){
oUl[j].style.display = "none";
oUl[this.index].style.display = "block";
oUl[j].style.backgroundColor = bgColorArr[this.index];
}
};
}
};
</script>
</head>
<body>
<div id="wrap">
<ul id="oLi" class="card_List clearfix">
<li class="current">1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
<div id="oUl" class="card_content">
<div style="display:block;">
11111111111111
</div>
<div>
22222222222
</div>
<div>
3333333333333
</div>
<div>
44444444444444444
</div>
</div>
</div>
</body>
</html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助。
- JS實(shí)現(xiàn)標(biāo)簽頁切換效果
- 最簡(jiǎn)單純JavaScript實(shí)現(xiàn)Tab標(biāo)簽頁切換的方式(推薦)
- Bootstrap 最常用的JS插件系列總結(jié)(圖片輪播、標(biāo)簽切換等)
- javascript實(shí)現(xiàn)標(biāo)簽切換代碼示例
- JS+DIV+CSS實(shí)現(xiàn)的經(jīng)典標(biāo)簽切換效果代碼
- js實(shí)現(xiàn)的tab標(biāo)簽切換效果代碼分享
- 簡(jiǎn)單純js實(shí)現(xiàn)點(diǎn)擊切換TAB標(biāo)簽實(shí)例
- js實(shí)現(xiàn)點(diǎn)擊切換TAB標(biāo)簽實(shí)例
- js(JavaScript)實(shí)現(xiàn)TAB標(biāo)簽切換效果的簡(jiǎn)單實(shí)例
- JS實(shí)現(xiàn)切換標(biāo)簽頁效果實(shí)例代碼
- JS實(shí)現(xiàn)的簡(jiǎn)單標(biāo)簽點(diǎn)擊切換功能示例
相關(guān)文章
javascript實(shí)現(xiàn)限制上傳文件大小
這篇文章主要介紹了javascript實(shí)現(xiàn)限制上傳文件大小的方法和示例,需要的朋友可以參考下2015-02-02
uniapp實(shí)現(xiàn)點(diǎn)擊出現(xiàn)彈窗功能實(shí)例
這篇文章主要給大家介紹了關(guān)于uniapp實(shí)現(xiàn)點(diǎn)擊出現(xiàn)彈窗功能的相關(guān)資料,UniApp框架中提供了兩種不同類型的彈出框,以幫助我們滿足不同的需求,需要的朋友可以參考下2023-08-08
JavaScript利用生成器函數(shù)實(shí)現(xiàn)優(yōu)雅處理異步任務(wù)流
Generators?是?JavaScript?中的一種特殊函數(shù),它們可以暫停執(zhí)行并根據(jù)需要生成多個(gè)值,本文將詳細(xì)介紹?generators?的作用、用法以及與其他語言特性的配合使用,希望對(duì)大家有所幫助2023-07-07
JavaScript兩種axios取消請(qǐng)求方式小結(jié)
本文主要介紹了JavaScript兩種axios取消請(qǐng)求方式小結(jié),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-03-03
js實(shí)現(xiàn)不提交表單獲取單選按鈕值的方法
這篇文章主要介紹了js實(shí)現(xiàn)不提交表單獲取單選按鈕值的方法,涉及javascript鼠標(biāo)事件及頁面元素屬性操作的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08
JS簡(jiǎn)單實(shí)現(xiàn)點(diǎn)擊跳轉(zhuǎn)登陸郵箱功能的方法
這篇文章主要介紹了JS簡(jiǎn)單實(shí)現(xiàn)點(diǎn)擊跳轉(zhuǎn)登陸郵箱功能的方法,涉及js針對(duì)hash表的遍歷與頁面元素屬性動(dòng)態(tài)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-10-10
js判斷請(qǐng)求的url是否可訪問,支持跨域判斷的實(shí)現(xiàn)方法
下面小編就為大家?guī)硪黄猨s判斷請(qǐng)求的url是否可訪問,支持跨域判斷的實(shí)現(xiàn)方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-09-09

