欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2017年05月23日 16:06:35   作者:Div_ma  
這篇文章主要為大家詳細(xì)介紹了js編寫(xiě)選項(xiàng)卡效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了js選項(xiàng)卡效果的具體代碼,供大家參考,具體內(nèi)容如下

<!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 class='box'>
   <input type="button" value='按鈕1' class='onclick'/>
   <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');

  });
 });

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論