zoukankan      html  css  js  c++  java
  • JS当页换图片(分析href所给的信息)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
      <meta http-equiv="content-type" content="text/html; charset=utf-8" />
      <title>Image Gallery</title>
        <script type="text/javascript" src="scripts/showPic.js"></script>
    </head>
    <body>
      <h1>Snapshots</h1>
      <ul>
        <li>
          <a href="images/fireworks.jpg" title="A fireworks display" onclick="showPic(this); return false;">Fireworks</a>
        </li>
        <li>
          <a href="images/coffee.jpg" title="A cup of black coffee" onclick="showPic(this); return false;">Coffee</a>
        </li>
        <li>
          <a href="images/rose.jpg" title="A red, red rose" onclick="showPic(this); return false;">Rose</a>
        </li>
        <li>
          <a href="images/bigben.jpg" title="The famous clock" onclick="showPic(this); return false;">Big Ben</a>
        </li>
      </ul>
      <img id="placeholder" src="images/placeholder.gif" alt="my image gallery" />
      <p id="description">Choose an image.</p>
    </body>
    </html>

    showPic.js文件

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

    JQuery的图片切换效果要漂亮很多:
    http://www.cnblogs.com/lhb25/p/50-jquery-plugins-f.html
    http://tympanus.net/Development/ImageTransitions/

  • 相关阅读:
    24、合并两个有序链表
    23、反转链表
    22、删除链表的倒数第N个节点
    21、删除链表中的节点
    18、实现strStr()
    17、字符串转换整数 (atoi)
    15、有效的字母异位词
    16、验证回文字符串
    14、字符串中的第一个唯一字符
    mybatis入门(七)----延迟加载
  • 原文地址:https://www.cnblogs.com/findumars/p/3164224.html
Copyright © 2011-2022 走看看