久久96国产精品久久久-久久发布国产伦子伦精品-久久精品国产精品青草-久久天天躁夜夜躁狠狠85麻豆

技術(shù)員聯(lián)盟提供win764位系統(tǒng)下載,win10,win7,xp,裝機(jī)純凈版,64位旗艦版,綠色軟件,免費(fèi)軟件下載基地!

當(dāng)前位置:主頁(yè) > 教程 > 服務(wù)器類 >

js編寫(xiě)選項(xiàng)卡效果教程

來(lái)源:技術(shù)員聯(lián)盟┆發(fā)布時(shí)間:2017-09-13 00:08┆點(diǎn)擊:

<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <style> *{ margin:0; padding:0; } .box{ margin:50px; } .box div{ display:none; width: 200px; height: 200px; border:1px solid black; } .onclick{ background:red; } input{ border:1px solid #666; padding:2px; } </style> </head> <body> <div> <input type="button" value='按鈕1'/> <input type="button" value='按鈕2' /> <input type="button" value='按鈕3' /> <div style="display:block">1</div> <div>2</div> <div>3</div> </div> </body> <script> var ipt=document.getElementsByTagName('input'); //獲取所有的按鈕標(biāo)簽 var oDiv=document.getElementsByClassName('box')[0]; //獲取box標(biāo)簽 var aDiv=oDiv.getElementsByTagName('div'); //獲取box下面的所有div標(biāo)簽 for(var i=0;i<ipt.length;i++){ //使用for循環(huán) 遍歷所有的input按鈕 ipt[i].index=i; //定義索引為i; ipt[i].onclick=function(){ //點(diǎn)擊事件 for(var j=0;j<ipt.length;j++){ //清除所有的樣式 aDiv[j].style.display='none'; ipt[j].className=''; } //設(shè)置adiv的樣式和input的背景樣式 aDiv[this.index].style.display='block'; ipt[this.index].className='onclick'; } } </script> </html>

補(bǔ)充JQ的做法:

$(function(){ $('.box').find('input').click(function(){ $('.box').find('input').attr('class',''); $(this).attr('class','onclick'); $('.box').find('div').css('display','none'); $('.box').find('div').eq($(this).index()).css('display','block'); }); });