jq练习-点击改变图片

Posted 铜镜123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jq练习-点击改变图片相关的知识,希望对你有一定的参考价值。

 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>

 

 

以上是关于jq练习-点击改变图片的主要内容,如果未能解决你的问题,请参考以下文章