首页 > JS菜鸟看书的时候对自己照书上抄的代码有问题 Javascript DOM 编程艺术 求大神解答 困扰了一晚上

JS菜鸟看书的时候对自己照书上抄的代码有问题 Javascript DOM 编程艺术 求大神解答 困扰了一晚上

这是我的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;
这块删掉就可以正常运行函数 加上之后就运行不了 重打了好多次 也检查了 还是
不行 只好求助 那位大哥帮忙看下`

<p id="discription">Choose an image.</p>

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

【热门文章】
【热门文章】