JS菜鸟看书的时候对自己照书上抄的代码有问题 Javascript DOM 编程艺术 求大神解答 困扰了一晚上
迷茫
迷茫 2017-04-10 16:51:30
[JavaScript讨论组]

这是我的HTML文件

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Image Gallery</title>
</head>
<body>
<h1>Snapshots</h1>
<ul>
<li>
<a href="images/fireworks.jpg" onclick="showPic(this); return false;" title="A fireworks display">Fireworks</a>
</li>
<li>
<a href="images/coffee.jpg" onclick="showPic(this); return false;" title="A cup of black coffee">Coffee</a>
</li>
<li>
<a href="images/rose.jpg" onclick="showPic(this); return false;" title="a red,red rose">Rose</a>
</li>
<li>
<a href="images/bigben.jpg" onclick="showPic(this); return false;" title="The famous clock">Big Ben</a>
</li>
</ul>
<image id="placeholder" src="images/placeholder.gif" alt="my image gallery"/>
<p id="discription">Choose an image.</p>
<script src="scripts/showPic.js"></script>
</body>
</html>

这是我的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;

}

我把`var text=whichpic.getAttribute("title");
    var description=document.getElementById("description");
    description.firstChild.nodeValue=text;
这块删掉就可以正常运行函数 加上之后就运行不了 重打了好多次 也检查了 还是
不行 只好求助 那位大哥帮忙看下`
迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

全部回复(1)
ringa_lee
<p id="discription">Choose an image.</p>

这一句的id值应为"description",拼写错误

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号