如何製作網頁中的選項卡?

來源:互聯網
上載者:User

標籤:

1. 做什嗎?

  用選擇按鈕切換圖片。 具體效果如下:

  

   

2. 工具

  用記事本,或者Dreamweaver( 如果害怕自己敲錯字母~),來編寫代碼。

  用Firefox瀏覽器做調試。 我是這麼試的, 不得不說頁面做得醜死了。

3. 思路

  首先用HTML把選項按鈕和圖片都建立出來, 然後編寫JS, 把選項按鈕和顯示圖片的事件綁定起來, 其中事件的思路是關閉其他圖片,開啟對應的圖片。

4. 代碼

  

<head><title>一行白鷺上青天</title></head><body><br/><div id="contentId" style="margin-left:20px"><div style="float:left;padding-left:30px" name="pic"><img src="./apple.jpg" alt="誘人的蘋果"/></div><div style="float:left;padding-left:60px" name="pic"><img src="./wine.jpg" alt="紫晶酒" width="200px" height="210px"/></div><div style="float:left;padding-left:10px" name="pic"><img src="./lemon.jpg" alt="燦爛的微笑"/></div></div><script>window.onload=function(){var heads = document.getElementsByName( ‘fruit‘ );var contents = document.getElementsByName( ‘pic‘ );var content = document.getElementById( ‘contentId‘ );var i,j;/*** 關閉所有內容*/content.style.display = "none";/*** 把內容和表頭綁定*/for( i = 0;  i < heads.length;  i ++ ){heads [i].index = i;heads [i].onclick = function(){content.style.display = "block"; //開啟內容框for( j = 0;  j < contents.length;  j ++ ){contents [j].style.display = "none";}contents [this.index].style.display = "block";};}}</script></body>

 

如何製作網頁中的選項卡?

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.