<!doctype html><html><head><meta charset="utf-8" /><title>測試</title><style type="text/css">body{ font-family:"Helvetica","Arial",serif;color:#333;background-color:#ccc;margin:1em 10%;}h1{ color:#333;?background-color:transparent; ?}?a{ color:#60; background-color:transparent; font-weight:bold; text-decoration:none;}?ul{ padding:0;}?li{ float:left;?padding:1em;?list-style:none;??}??img{ display:block;??clear:both;???}?</style></head><body><!-- background-color:transparent; 背景顏色--><h1>Snapshots</h1><ul><li><a href="../Pictures/44f39c9fbda334ac0465dcb9daf20920e2000482cc3c-vFqdh3_fw580.jpg" title="zhendeceshi" id="Td">Fireworks</a></li><li><a href="../Desktop/新建文件夾/7.png" title="dierci" id="Td">Coffee</a></li><li><a href="../Desktop/新建文件夾/新建文件夾 (4)/video_20160424_092705.mp4" title="woerzi" id="Td">Rose</a></li><li><a href="多項目整合營銷.png" title="heqianmianyiyang" id="Td">Big Ben</a></li></ul><img src="images/place.gif" alt="my image gallery" width="436" height="209" id="placheolder" /><script>?function YY(lilike){?? var aNd=?lilike.getAttribute("href");?? var iRd=document.getElementById("placheolder");?? iRd.setAttribute("src",aNd);? }?? var eRy=document.getElementsByTagName("a");? for(var i=0;i<eRy.length;i++){? eRy[i].onclick=function(){?? YY(this); //寫了方法解決了問題,但我也不知道是怎么做到的。?? return false;?? ?? ?? ?? }}/*var cDy={?//添加句柄?Wanna:function(element,type,handler){???? ??if(element.addEventListener){????element.addEventListener(type,handler,false);????????????}else if(element.attachEvent){?????element.attachEvent('on'+type,handler);??????????}else{??????elemment['on'+type]=handler; ????????????}??????????}?}cDy.Wanna(eRy,'click', YY(this));*/</script></body></html>雖然把問題解決了,但是還是不了解具體哪個方式解決問題的關(guān)鍵,還要DOM2不知道怎么解決這些問題,已經(jīng)試了好多次了,可能是需要加個循環(huán),但我想知道為什么加了循環(huán)后就可以實現(xiàn)方案了。
DOM0級onclick事件操作問題與DOM2級實現(xiàn)問題方案
亂也
2016-11-17 22:19:34