麻煩幫看下哪里出了問(wèn)題,謝謝
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Image Gallery</title>
<link rel="stylesheet" type="text/css" href="css/index.css">
</head>
<body>
<h1>Snapshots</h1>
<div class="image-box">
<ul id="imageGallery">
<li><a href="images/3.jpg" title="鞋子">鞋子</a></li>
<li><a href="images/5.jpg" title="行李箱">行李箱</a></li>
<li><a href="images/7.jpg" title="手機(jī)">手機(jī)</a></li>
<li><a href="images/11.jpg" title="體恤衫">體恤衫</a></li>
</ul>
<!-- <img id="placeholder" src="images/course5.jpg" alt="my Image Gallery"/> -->
</div>
<!-- <p id="description">Choose an image.</p> -->
? <script type="text/javascript" src="js/index.js"></script>
</body>
</html>
// 以下代碼那里錯(cuò)誤?
function addLoadEvent(func){
var oldload=window.onload;
if(typeof window.onload!="function"){
window.onload=func;
}else{
window.onload=function(){
oldload();
func();
}
}
}
function preparePlaceholder(){
if(!document.createElement) return false;
if(!document.createTextNode) return false;
if(!document.getElementById) return false;
if(!document.getElementById("image-box")) return false;
var placeholder=document.createElement("img");
placeholder.setAttribute("id","placeholder");
placeholder.setAttribute("src","images/course5.jpg");
placeholder.setAttribute("alt","my Image Gallery");
var imageBox=document.getElementById("image-box");
imageBox.appendChild(placeholder);
var description=document.createElement("p");
description.setAttribute("id","description");
var txt=document.createElement("Choose an image.");
description.appendChild(txt);
document.body.appendChild(description);
}
function prepareGallery(){
if(!document.getElementById) return false;
if(!document.getElementsByTagName) return false;
if(!document.getElementById("imageGallery")) return false;
var imageGallery=document.getElementById("imageGallery");
var aLinks=imageGallery.getElementsByTagName("a");
for(var i=0;i<aLinks.length;i++){
aLinks[i].onclick=function(){
//showPic(this);
// console.log(this);
return showPic(this) ? false:true;
}
//aLinks[i].onkeypress=aLinks[i].onClick;
}?
}
//addLoad? ?Event(prepareGallery);
function showPic(whichpic){
if(!document.getElementById("placeholder")) return false;
var source=whichpic.getAttribute("href");
var placeholder=document.getElementById("placeholder");
placeholder.setAttribute("src",source);
if(document.getElementById("description")){
var text=whichpic.getAttribute("title")? whichpic.getAttribute("title"):"",
description=document.getElementById("description");
if(description.firstChild.nodeType==3){
description.firstChild.nodeValue=text;
}
}
return true;//如果description存在,它將會(huì)被更新,否則會(huì)忽略。
// window.onload=countBodyChild();//每點(diǎn)擊一次,彈出一次;
//countBodyChild();//每點(diǎn)擊一次,彈出一次;
}
addLoadEvent(preparePlaceholder);
addLoadEvent(prepareGallery);
body{
? ?padding:30px 0 0 100px;
}
ul,li{
list-style-type: none;;
}
li{
display:inline-block;
margin-right:50px;
}
a{
text-decoration:none;
color:#900;
font-weight: bold;
font-size:16px;
}
p{
font-size:20px;
font-weight:bold;
}
我想實(shí)現(xiàn)的是點(diǎn)擊li中的文字后,動(dòng)態(tài)的創(chuàng)建出placeholder對(duì)象和description對(duì)象,并將li中a連接的圖片顯示到place holder中,將a鏈接的title屬性中的文字顯示到description中,麻煩幫我看看為什么,我一點(diǎn)擊a鏈接就跳轉(zhuǎn)到新的頁(yè)面打開(kāi)圖片了。