原生js實(shí)現(xiàn)選項(xiàng)卡功能
效果圖:
代碼如下:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>原生js選項(xiàng)卡寫(xiě)法</title> <style> #div1 div{width: 200px;height: 200px;border: 1px solid #FF0000;display: none;} .active{background: red;} </style> <script> window.onload=function(){//原生js選項(xiàng)卡寫(xiě)法 var oDiv = document.getElementById('div1'); var aInput = document.getElementsByTagName('input'); var aCon = oDiv.getElementsByTagName('div'); for(var i=0;i<aInput.length;i++){ aInput[i].index = i; aInput[i].onclick = function(){ for(var i=0;i<aInput.length;i++){ aInput[i].className = ''; aCon[i].style.display = 'none'; } this.className= 'active'; aCon[this.index].style.display = 'block'; } } } </script> </head> <body> <div id="div1"> <input class="active" type="button" value="1" /> <input type="button" value="2"/> <input type="button" value="3"/> <div style="display: block;">11111111111</div> <div>22222222222</div> <div>333333333333</div> </div> </body> </html>
以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!
- Vue.js tab實(shí)現(xiàn)選項(xiàng)卡切換
- 使用vue.js寫(xiě)一個(gè)tab選項(xiàng)卡效果
- js鼠標(biāo)經(jīng)過(guò)tab選項(xiàng)卡時(shí)實(shí)現(xiàn)切換延遲
- 完美實(shí)現(xiàn)js選項(xiàng)卡切換效果(二)
- Vue.js組件tab實(shí)現(xiàn)選項(xiàng)卡切換
- JS實(shí)現(xiàn)的tab切換選項(xiàng)卡效果示例
- JS使用面向?qū)ο蠹夹g(shù)實(shí)現(xiàn)的tab選項(xiàng)卡效果示例
- js實(shí)現(xiàn)簡(jiǎn)單的選項(xiàng)卡效果
- js-tab選項(xiàng)卡
- js編寫(xiě)選項(xiàng)卡效果
相關(guān)文章
點(diǎn)擊頁(yè)面任何位置隱藏div的實(shí)現(xiàn)方法
下面小編就為大家?guī)?lái)一篇點(diǎn)擊頁(yè)面任何位置隱藏div的實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-09-09List the Codec Files on a Computer
List the Codec Files on a Computer...2007-06-06JavaScript動(dòng)態(tài)創(chuàng)建link標(biāo)簽到head里的方法
這篇文章主要介紹了JavaScript動(dòng)態(tài)創(chuàng)建link標(biāo)簽到head里的方法,分別介紹了使用jQuery的方法、使用原生javascript方法與IE特有的createStyleSheet方法等,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2014-12-12webpack-dev-server搭建本地服務(wù)器的實(shí)現(xiàn)
當(dāng)我們使用webpack打包時(shí),發(fā)現(xiàn)每次更新了一點(diǎn)代碼,都需要重新打包,我們希望本地能搭建一個(gè)服務(wù)器,本文就介紹如何使用webpack-dev-server搭建本地服務(wù)器,感興趣的可以了解一下2021-07-07undefined==null引發(fā)的兩者區(qū)別與聯(lián)系
undefined==null引發(fā)的兩者區(qū)別與聯(lián)系2007-12-12原生JS實(shí)現(xiàn)各種運(yùn)動(dòng)之勻速運(yùn)動(dòng)
這篇文章主要為大家詳細(xì)介紹了原生JS實(shí)現(xiàn)各種運(yùn)動(dòng)之勻速運(yùn)動(dòng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08深入理解JavaScript中的宏任務(wù)和微任務(wù)機(jī)制
JavaScript中的任務(wù)分為宏任務(wù)和微任務(wù),它們的執(zhí)行順序會(huì)影響代碼的執(zhí)行結(jié)果。了解它們的機(jī)制可以幫助我們更好地理解事件循環(huán)和異步編程,避免出現(xiàn)一些意想不到的錯(cuò)誤2023-05-05