jq-demo-点击改变图片

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="UTF-8">
 5         <title></title>
 6         <style>
 7             td, img {
 8                 width: 100px;
 9                 height: 100px;
10             }
11         </style>
12     </head>
13     <body>
14         <table border="1px" >
15             <tr>
16                 <td><img src="images/1.jpg"/></td>
17                 <td><img src="images/2.jpg"/></td>
18                 <td><img src="images/11.jpg"/></td>                
19             </tr>
20         </table>
21         <img id="showImg" src="images/1.jpg"/>
22 
23         <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
24         <script>
25             $(function(){
26                 $("tr img").click(function () {
27                     $("#showImg").attr("src", $(this).attr("src"));
28                     console.log($(this).index("tr img"));
29                 })
30             })
31             
32         </script>
33         
34     </body>
35 </html>

 

 

posted @ 2017-09-07 18:03  铜镜123  阅读(277)  评论(0编辑  收藏  举报