JS部分: <script>
function prepareGallery()
{
if(!document.getElementById("gallery"))return false;
if(!document.getElementsByTagName)return false;
var gallery=document.getElementById("gallery");
var links=gallery.getElementsByTagName("a");
for(i=0;i<links.length;i++)
{
links[i].onclick=function()
{
return !showpic(this);
}
}
}
function showpic(x)
{
var changepic=document.getElementById("placeholder");
var source=x.getAttribute("href");
changepic.setAttribute("src",source);
var description=document.getElementById("description");
var text=x.firstChild.nodeValue;
description.firstChild.nodeValue=text;
}
function addLoadEvent(func){
var oldonload=window.onload;
if (typeof window.onload!='function')
{
window.onload=func;
}
else{
window.onload=function()
{
oldonload();
func();
}
}
}
addLoadEvent(prepareGallery);
</script>HTML部分:<h1>标题</h1>
<ul id="gallery">
<li>
<a href="img/摆渡.jpg" title="摆渡人" >摆渡人</a>
</li>
<li>
<a href="img/城市.png" title="洛阳城" >洛阳城</a>
</li>
<li>
<a href="img/守卫.jpg" title="地狱口" >地狱口</a>
</li>
<li>
<a href="img/海怪.jpg" title="海上龙" >海上龙</a>
</li>
</ul>
<p id="description">选择一张图片</p>
<img id="placeholder" src="img/透明.png" alt="占位图"/>当links[i].onclick=function() { return !showpic(this); }部分为links[i].onclick=function(){showpic(this);return false;}时,是没有问题的。按照书上一改就完蛋,求大神们指点。多谢多谢多谢回答O(∩_∩)O
添加回答
举报
0/150
提交
取消