jQuery僅用3行代碼實現的顯示與隱藏功能完整執行個體,jquery3行

來源:互聯網
上載者:User

jQuery僅用3行代碼實現的顯示與隱藏功能完整執行個體,jquery3行

本文執行個體講述了jQuery僅用3行代碼實現的顯示與隱藏功能。分享給大家供大家參考。具體如下:

jQuery技術相當好使用,的確可以用很少的代碼實現想要的功能,比如這款經常用到的“顯示”與“隱藏”的功能,只需要3行代碼就實現了,確實夠給力。

運行效果如下:

線上示範地址如下:

http://demo.jb51.net/js/2015/jquery-simple-hide-show-style-demo/

具體代碼如下:

<!doctype html><html><head><meta charset="gbk" /><title>3行代碼實現顯示與隱藏</title><script type="text/javascript" src="jquery1.3.2.js"></script><style>  .showmore{ float:left;}  .cont .aa {  height: auto;  width: 400px;  border: 1px solid #000000;  margin-bottom: 10px;  padding-right: 10px;  padding-left: 10px;  float: left;  }  .cont .aa .a1 {  float: left;  height: 30px;  width: 300px;  }  .cont .aa .a2 {  height: 30px;  width: 350px;  float: left;  display:none;  } </style></head><body><div class="cont"> <div class="aa">  <div class="a1">tab1</div>  <div class="showmore"><a href="#"><span>顯示</span></a></div>  <div class="a2">詳細說明:今天你要嫁給我嘛~</div> </div> <div class="aa">  <div class="a1">tab2</div>  <div class="showmore" ><a href="#"><span>顯示</span></a></div>  <div class="a2">詳細說明:北京、上海四日遊</div> </div> <div class="aa">  <div class="a1">tab3</div>  <div class="showmore" ><a href="#"><span>顯示</span></a></div>  <div class="a2">詳細說明:河南是華夏文明的根源</div> </div></div><script>$(".showmore a span").mouseover(function(e){ $(this).html(["顯示", "隱藏"][this.hutia^=1]); $(this.parentNode.parentNode).next().toggle(); e.preventDefault();});</script></body></html>

希望本文所述對大家的jQuery程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.