<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>Test Page</title> <script type="text/javascript" src="js/jquery-1.11.1.min.js"></script> <link rel="stylesheet" type="text/css" href="css/common.css" /> </head> <script type="text/javascript"> $(function(){ $(".thumbs a").click(function(){ var largePath = $(this).attr("href"); var largeAlt = $(this).attr("title"); $("#largeImg").attr({ src:largePath, alt:largeAlt }); return false; }); }); </script> <body> <h2>图片预览</h2> <p id="largeImg"> <img src="images/img1-lg.jpg" alt="largeImg" /> </p> <p class="thumbs"> <a href="images/img2-lg.jpg" title="Image2"><img src="images/img2-thumb.jpg" /></a> <a href="images/img3-lg.jpg" title="Image3"><img src="images/img3-thumb.jpg" /></a> <a href="images/img4-lg.jpg" title="Image4"><img src="images/img4-thumb.jpg" /></a> <a href="images/img5-lg.jpg" title="Image5"><img src="images/img5-thumb.jpg" /></a> <a href="images/img6-lg.jpg" title="Image6"><img src="images/img6-thumb.jpg" /></a> </p> </body> </html>
我写到img里面,也还是没有效果,咋回事
O(∩_∩)O~,我刚刚也发现了,没想到你自己回答了!我也时常犯这种小错误!
我把id="largeImg"写到p标签里了,所以没有效果