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

  • 相关阅读:
    做报表,写Sql语句的一点收获
    ORACLE PL/SQ入门
    用Visual C#实现P2P应用程序
    css资源网站收集推荐
    Ubuntu 蓝牙全攻略
    Asp.Net细节性问题技巧精萃
    Asp.net Request获取服务器变量的方法
    如何将flash插入到Excel文件中
    XP远程桌面连接强制登录
    flash研究(三)——Falsh与JavaScript交互
  • 原文地址:https://www.cnblogs.com/peterli2013/p/3183948.html
Copyright © 2020-2023  润新知