<!DOCTYPE html>
<html>
<head>
<title>test4.4</title>
<script type="text/javascript" src="D:\draft\primaryJavascript\test44.js"></script>
</head>
<body>
<h1>Quagmire</h1>
<ul>
<li>
<a href="D:\draft\primaryJavascript\fireworks.jpg" onclick="showPig(this); return false;" title="a fireworks display">BoomShakaLaka</a>
</li>
<li>
<a href="D:\draft\primaryJavascript\coffee.jpg" title="a cup of black coffee" onclick="showPig(this);return false;">WannaDie?</a>
</li>
<li>
<a href="D:\draft\primaryJavascript\BigBen.jpg" onclick="showPig(this);return false;" title="the famous clock">the giant clock is going to hit you directly.</a>
</li>
<img id="placeholder" src="D:\draft\primaryJavascript\placeholder.jpg"/ alt="my image gallery"/>
</ul>
<p id="description">Choose an image.</p>
</body>
</html>
js代码
function showPig(whichpig){
var source=whichpig.getAttribute("href");
var placeholder=document.getElementById("placeholder");
placeholder.setAttribute("src",source);
}
js代码新增3条语句后 原先点击图片链接停留在当前页面和placeholder转为链接图片功能失效
function showPig(whichpig){
var source=whichpig.getAttribute("href");
var placeholder=document.getElementById("placeholder");
placeholder.setAttribute("src",source);
**var text=whichpig.getAttribute("title");
var description=getElementById("description");
description.firstChild.nodeValue=text;**
}
有趣的是,我对新增的三条语句逐条注释看看是哪条语句使得所有函数功能失效。是这一句:
var description=getElementById("description");
我使用的编辑器是sublime text3.
那么如何才能实现所有功能呢?
应该是var description=document.getElementById("description");这样吧