zoukankan      html  css  js  c++  java
  • javascript DOM(2) 一个网页上切换显示不同的图片或文本

    摘自: javascript DOM 编程艺术

    1. 在一个网页上切换显示不同的图片

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Image Gallery</title>
    <script type="text/javascript" src="script/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 a image.</p>
    </body>
    </html>

    showPic.js

    function showPic(whichpic) {

    var source = whichpic.getAttribute("href");
    var placeholder = document.getElementById("placeholder");
    placeholder.setAttribute("src",source);
    }

    2.在同一个网页上切换显示不同的文本

    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;
    }

  • 相关阅读:
    STM32学习笔记之__attribute__ ((at())绝对定位分析
    CRC 自动判断大端 小端
    AT命令控制上网 PDP
    PPP PDP 及GPRS
    Renesas CAT CONFIG
    AT指令(二)
    字节对齐问题
    IntelliJ Idea 常用快捷键列表
    solr6.6 导入 文本(txt/json/xml/csv)文件
    solr6.6 导入 pdf/doc/txt/json/csv/xml文件
  • 原文地址:https://www.cnblogs.com/peterli2013/p/3183948.html
Copyright © 2011-2022 走看看