为了账号安全,请及时绑定邮箱和手机立即绑定

图片点击切换效果怎么不行啊,求帮忙看看

图片点击切换效果怎么不行啊,求帮忙看看

慕粉4084340 2016-10-23 20:05:43
本来在 showPic函数里不修改title属性可以正常运行,但是一加上description的文字可以运行,但是一加上后面那一段就不行了,求帮忙<!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","默认图片");        var description=document.createElement("p");         var description=document.createElement("id","description");         var desctext=document.createTextNode("默认图片");         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>
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 1319 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信