Art Gallery 2.0

今天终于搞明白之前为什么不能用外部的js文件了src后面接的直接就是外部的地址,不需要加上什么scripts/****之类的
还有引用js的时候js的文件是不需要再加上什么<script>的标签的
辣鸡书籍,毁我青春


html部分

<!DOCTYPE html>                     
<html lang="en">
    <head>
        <meta charset="utf-8"/>
        <title>Image</title>    
    <!--
        <script>
                    function showPic(whichpic){
                var source = whichpic.getAttribute("href");
                var placeholder = document.getElementById("placeholder");
                placeholder.setAttribute("src",source);
            }
            </script>
            这是把脚本写在内部的方法
        -->
                <script type="text/javascript" src="showPic.js"></script>
    </head>
    <body >

        <h1>Snashots</h1>
        <ul>
            <li>
                <a href="1518aa12ee9284ce5d45d818364740ac.jpg" onclick="showPic(this);return false;" title="Wine Party">wine</a>
            </li>
            <li>
                <a href="21296024e76ff4f17624bbda7dd4125e.jpeg" onclick="showPic(this);return false;"title="pretty gril">pretty gril</a>
            </li>
            <img id="placeholder" src="images/placeholder.gif" alt="my art gallery"/>   
        </ul>
        <p id = "description">Choose an image.</p>


    </body>
</html>

script部分

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

新增加的功能是可以实现下面的句子的文本内容发生变化
可以从原来的Choose an image 到 你选择的图像的名字

学习的新的知识或者说是名词

  • childNode
  • nodeValue
  • nodeType(有1 2 3 3个值,分别是元素节点,属性节点,文本节点)
  • firstChild/lastChild
  • onload
  • window

    接下来打算看看js
    再把大话数据结构看了
    再接着就是操作系统的data structure
    come on!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值