国产成人精品18p,天天干成人网,无码专区狠狠躁天天躁,美女脱精光隐私扒开免费观看

JavaScript中圖片庫的示例分析

發(fā)布時(shí)間:2021-09-04 11:55 來(lái)源:億速云 閱讀:0 作者:小新 欄目: 開(kāi)發(fā)技術(shù)

這篇文章將為大家詳細講解有關(guān)JavaScript中圖片庫的示例分析,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

一、一個(gè)javascript 圖片庫實(shí)例,下面是效果圖

點(diǎn)擊頂部導航,會(huì )在本頁(yè)面進(jìn)行刷新圖片,然后,在底部會(huì )顯示文本的變化

二、下面是代碼

1、gallery.html代碼

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title></title>
    <script type="text/javascript" src="js/showPic.js"></script>
    <link rel="stylesheet" type="text/css" href="css/layout.css" rel="external nofollow" />
  </head>
  <body>
    <h2>Snapshots</h2>
    <ul>
      <li>
        <a href="img/a.jpg" rel="external nofollow" title="Hongse Fengye" onclick="showPic(this);return false;">紅色楓葉</a>
      </li>
      <li>
        <a href="img/b.jpg" rel="external nofollow" title="Huangse Fengye" onclick="showPic(this); return false;">黃色楓葉</a>
      </li>
      <li>
        <a href="img/c.jpg" rel="external nofollow" title="Hongse Shu" onclick="showPic(this); return false;">紅色樹(shù)</a>
      </li>
      <li>
        <a href="img/d.jpg" rel="external nofollow" title="Lanse Fengye" onclick="showPic(this);return false;">藍色楓葉</a>
      </li>
    </ul>
    <img src="img/3302-106.jpg" id="placeholder" alt="My Gallery"/>
    <p id="description">Choose an image</p>
  </body>
</html>

2、showPics.js代碼

function showPic(whichpic){
  var sorce=whichpic.getAttribute("href");
  var placeholder=document.getElementById("placeholder");
  placeholder.setAttribute("src",sorce);
  var text=whichpic.getAttribute("title");
  var description=document.getElementById("description");
  description.firstChild.nodeValue=text;
}

3、layout.css代碼

img{
  width: 600px;
}
body{
  font-family: helvetica,arial,serif;
  color: #333;
  background-color: #ccc;
  margin: 1em 10%;
}
h2{
  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;
}
img{
  display: block;
  clear: both;
}

三、幾個(gè)新的DOM屬性

1、childNodes

獲得 body 元素的子節點(diǎn)集合:

document.body.childNodes;

2、nodeType

獲得 body 元素的節點(diǎn)類(lèi)型:

document.body.nodeType;

3、nodeValue

nodeValue 屬性設置或返回指定節點(diǎn)的節點(diǎn)值。

4、firstChild、lastChild

firstChild 屬性返回指定節點(diǎn)的首個(gè)子節點(diǎn),以 Node 對象。

lastChild 屬性返回指定節點(diǎn)的最后一個(gè)子節點(diǎn),以 Node 對象。

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自互聯(lián)網(wǎng)轉載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權請聯(lián)系QQ:712375056 進(jìn)行舉報,并提供相關(guān)證據,一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容。

亚洲一区二区三区成人网站| 动漫av一区二区在线观看| 影音先锋色中色| 试看120秒免费体验区| 色天天躁夜夜躁天干天干| 亚洲女同性同志熟女|