本來在 showPic函數(shù)里不修改title屬性可以正常運(yùn)行,但是一加上description的文字可以運(yùn)行,但是一加上后面那一段就不行了,求幫忙<!doctype html><html><head>??? <meta charset="UTF-8">??? <title>Document</title></head><body>??? <ul id="imagegellery">??????? <li>??????????? <a href="1.jpg" title="第1張圖片">第1張圖片</a>??????? </li>???????? <li>??????????? <a href="2.jpg" title="第2張圖片">第2張圖片</a>??????? </li>???????? <li>??????????? <a href="3.jpg" title="第3張圖片">第3張圖片</a>??????? </li>??? </ul><script>??? function addLoadEvent(func){??????? var oldonload=window.onload;??????? if(typeof window.onload!='function'){??????????? window.onload=func;??????? }else{??????????? window.onload=function(){??????????????? oldonload();??????????????? func();??????????? }??????? }??? }??? function insertAfter(newElement,targetElement){??????? var parent=targetElement.parentNode;??????? if(parent.lastChild==targetElement){??????????? parent.appendChild("newElement");??????? }else{??????????? parent.insertBefore(newElement,targetElement.nextSibling);??????? }??? }??? function preparePlaceholder(){??????? var placeholder=document.createElement("img");??????? placeholder.setAttribute("id","placeholder");??????? placeholder.setAttribute("src","4.jpg");??????? placeholder.setAttribute("alt","默認(rèn)圖片");??????? var description=document.createElement("p");???????? var description=document.createElement("id","description");???????? var desctext=document.createTextNode("默認(rèn)圖片");???????? description.appendChild(desctext);???????? var gallery=document.getElementById("imagegellery");???????? insertAfter(placeholder,gallery);???????? insertAfter(description,gallery);??? }??? function preareGallery(){??? var gallery=document.getElementById("imagegellery");??? var links=gallery.getElementsByTagName("a")??? for (var i = 0; i < links.length; i++) {??????? links[i].onclick=function(){??????????? return showPic(this);??????? }??????? links[i].onkeypress=links[i].onclick;??? };}function showPic(whichpic){??? var source=whichpic.getAttribute("href");??? var placeholder=document.getElementById("placeholder")???? placeholder.setAttribute("src",source)???? if(whichpic.getAttribute("title")){???? var text=whichpic.getAttribute("title");}???? else{var text="";}???? var description=document.getElementById("description")???? if(description.firstChild.nodeType==3){???? description.firstChild.nodeValue=text;?}??? ???? return false;}addLoadEvent(preparePlaceholder)addLoadEvent(preareGallery)</script>?? ?</body></html>
圖片點(diǎn)擊切換效果怎么不行啊,求幫忙看看
慕粉4084340
2016-10-23 20:05:43