亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

麻煩幫看下哪里出了問題,謝謝

<!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="手機">手機</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>

// 以下代碼那里錯誤?

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存在,它將會被更新,否則會忽略。

// window.onload=countBodyChild();//每點擊一次,彈出一次;

//countBodyChild();//每點擊一次,彈出一次;

}

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;

}

我想實現的是點擊li中的文字后,動態的創建出placeholder對象和description對象,并將li中a連接的圖片顯示到place holder中,將a鏈接的title屬性中的文字顯示到description中,麻煩幫我看看為什么,我一點擊a鏈接就跳轉到新的頁面打開圖片了。

正在回答

舉報

0/150
提交
取消

麻煩幫看下哪里出了問題,謝謝

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號