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

javascript實(shí)現(xiàn)點(diǎn)擊小圖顯示大圖

 更新時(shí)間:2020年11月29日 09:02:32   作者:小小阿星  
這篇文章主要為大家詳細(xì)介紹了javascript實(shí)現(xiàn)點(diǎn)擊小圖顯示大圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了javascript實(shí)現(xiàn)點(diǎn)擊小圖顯示大圖的具體代碼,供大家參考,具體內(nèi)容如下

<!DOCTYPE html>
<html>
<head lang="en">
 <meta charset="UTF-8">
 <title></title>
 <style type="text/css">
  body {
   font-family: "Helvetica", "Arial", serif;
   color: #333;
   background-color: #ccc;
   margin: 1em 10%;
  }

  h1 {
   color: #333;
   background-color: transparent;
  }

  a {
   color: #c60;
   background-color: transparent;
   font-weight: bold;
   text-decoration: none;
  }

  ul {
   padding: 0;
  }

  li {
   float: left;
   padding: 1em;
   list-style: none;
  }

  #imagegallery {

   list-style: none;
  }

  #imagegallery li {
   margin: 0px 20px 20px 0px;
   padding: 0px;
   display: inline;
  }

  #imagegallery li a img {
   border: 0;
  }
 </style>
</head>
<body>

<h2>
 美女畫(huà)廊
</h2>

<ul id="imagegallery">
 <li>
  <a href="images/1.jpg" rel="external nofollow" title="美女A">
 <img src="images/1-small.jpg" width="100" alt="美女1"/>
  </a>
 </li>
 <li><a href="images/2.jpg" rel="external nofollow" title="美女B">
  <img src="images/2-small.jpg" width="100" alt="美女2"/>
 </a></li>
 <li><a href="images/3.jpg" rel="external nofollow" title="美女C">
  <img src="images/3-small.jpg" width="100" alt="美女3"/>
 </a></li>
 <li><a href="images/4.jpg" rel="external nofollow" title="美女D">
  <img src="images/4-small.jpg" width="100" alt="美女4"/>
 </a></li>
</ul>


<div style="clear:both"></div>
<!--顯示大圖的-->
<img id="image" src="images/placeholder.png" alt="" width="450"/>
<p id="des">選擇一個(gè)圖片</p>
<script>
 // 獲取ul元素對(duì)象
 var imagegallery = document.getElementById("imagegallery")
 // 獲取a元素 數(shù)組
 var a = imagegallery.getElementsByTagName("a")
 
 // 獲取大圖元素對(duì)象
 var image = document.getElementById("image")
 
 // 獲取p標(biāo)簽
 var des = document.getElementById("des")
 // console.log(imagegallery,a)
 
 // 遍歷數(shù)組元素為每一個(gè)a鏈接注冊(cè)點(diǎn)擊事件
 for(var i = 0; i < a.length; i++){
 a[i].onclick = function(){
  // 將a鏈接中的href中的值賦值給大圖的src屬性
  image.src = this.href
  // 將a鏈接中的title的值作為內(nèi)容賦值給p標(biāo)簽
  des.innerHTML = this.title
  return false
 }
 }
 //點(diǎn)擊a標(biāo)簽,把a(bǔ)標(biāo)簽中的href的屬性值給id為image的src屬性
 //把a(bǔ)的title屬性的值給id為des的p標(biāo)簽賦值
 //阻止超鏈接默認(rèn)的跳轉(zhuǎn)
  // return false;

</script>

</body>
</html>

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

相關(guān)文章

最新評(píng)論