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

  • 相关阅读:
    [极客大挑战 2019]EasySQL
    BUUCTF-[强网杯 2019]随便注-wp
    BUUCTF-[HCTF 2018]WarmUp-wp
    wp-2017ssrfme
    < 算法笔记(晴神宝典)
    < python音频库:Windows下pydub安装配置、过程出现的问题及常用API >
    < JAVA
    < 博客园自定义皮肤装饰代码
    <编译原理
    < AlexNet
  • 原文地址:https://www.cnblogs.com/peterli2013/p/3183948.html
Copyright © 2020-2023  润新知