<title>无标题文档</title><script type="text/javascript">function shopPic(whichpic){var placeholder=document.getElementById("placeholder");placeholder.setAttribute("src",whichpic.getAttribute("href"));}</script></head><body><h1>Snapshot</h1><ul><li><a href="image/1.jpg" title="1">1</a></li><li><a href="image/2.jpg" title="2">2</a></li><li><a href="image/3.jpg" title="3">3</a></li><li><a href="image/4.jpg" title="4">4</a></li></ul><img id="placeholder" src="image/3.jpg" alt="占位符" /></ul></body></html>
2 回答
Ewall_
TA贡献27条经验 获得超9个赞
你事件onclick都没有,哪里来的图片转换
<body> <h1>Snapshot</h1> <ul id="picgroup"> <li><a href="image/1.jpg" title="1">1</a></li> <li><a href="image/2.jpg" title="2">2</a></li> <li><a href="image/3.jpg" title="3">3</a></li> <li><a href="image/4.jpg" title="4">4</a></li> </ul> <img id="placeholder" src="image/3.jpg" alt="占位符" /> <script type="text/javascript"> function picgroup(){ var picgroup=document.getElementById("picgroup"); var aLinks=picgroup.getElementsByTagName("a"); for(i=0;i<aLinks.length;i++){ aLinks.onclick=function(){ showPic(this); return flase; } } } function showPic(whichpic){ var placeholder=document.getElementById("placeholder"); placeholder.setAttribute("src",whichpic.getAttribute("href")); } </script> </body>
_潇潇暮雨
TA贡献646条经验 获得超225个赞
需要阻止默认事件,下面是代码:
<html> <title>无标题文档</title> <script type="text/javascript"> function shopPic(whichpic){ event.preventDefault() var placeholder=document.getElementById("placeholder"); console.log(whichpic.getAttribute("href")) placeholder.setAttribute("src",whichpic.getAttribute("href")); } </script> </head> <body> <h1>Snapshot</h1> <ul> <li><a href="image/1.jpg" title="1" onclick="shopPic(this)">1</a></li> <li><a href="image/2.jpg" title="2" onclick="shopPic(this)">2</a></li> <li><a href="image/3.jpg" title="3" onclick="shopPic(this)">3</a></li> <li><a href="image/4.jpg" title="4" onclick="shopPic(this)">4</a></li> </ul> <img id="placeholder" src="image/3.jpg" alt="占位符" /> </ul> </body> </html>
添加回答
举报
0/150
提交
取消