表格行点击变背景色、选择删除、全选删除、图片原图显示
效果显示:
代码贴上:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <meta content=" keywords" /> <meta content="description" /> </head> <script type="text/javascript" src="https://www.jb51.net/jquery-1.7.2.min.js"></script> <style type="text/css"> body{font-size:12px} table{width:360px;border-collapse:collapse} table tr th,td{border:solid 1px #666;text-align:center} table tr td img{border:solid 1px #ccc;padding:3px;width:42px;height:60px;cursor:pointer} table tr td span{float:left;padding-left:12px} table tr th{background-color:#ccc;height:32px;background-color:#fff} .clsImg{position:absolute;border:solid 1px #ccc;padding:3px;background-color:#eee;display:none;cursor:pointer} .btn{border:solid 1px #666;padding:2px;width:50px;filter:progd:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=#fff,EndColorStr=#ECE9D8);cursor:pointer} </style> <body> <script type="text/javascript"> $(function(){ //点击表格行变色 $('tr').click(function(){ if((this.style.backgroundColor=='')||(this.style.backgroundColor=='rgb(255, 255, 255)')){ this.style.cssText='background-color:#CCC'; }else{ this.style.cssText='background-color:#fff'; } }) //放大图显示 $('.a').mousemove(function(e){ $('#imgTip').show().attr('src',this.src); $('#imgTip').css({'top':(e.pageY+5)+'px','left':(e.pageX+5)+'px'}); }); $('.a').mouseover(function(e){ $('#imgTip').show().attr('src',this.src); $('#imgTip').css({'top':(e.pageY+5)+'px','left':(e.pageX+5)+'px'}); }); $('.a').mouseout(function(){ $('#imgTip').hide(); }); //点击全选 $('#checkAll').click(function(){ if(this.checked){ $(':checkbox').attr('checked',true); }else{ $(':checkbox').attr('checked',false); } }); //删除部分与全部 $('.btn').click(function(){ if($('#checkAll').attr('checked')){ $('table tr td :checkbox:not("#checkAll")').each(function(index){ $('#'+this.value).remove(); }); }else{ $(':checkbox:not("#checkAll")').each(function(index){ if(this.checked){ $('#'+this.value).remove(); } }) } }); }); </script> <table> <tr> <th>选项</th> <th>编号</th> <th>封面</th> <th>购书人</th> <th>性别</th> <th>够书价</th> </tr> <tr> <td><input type="checkbox" value="0" /></td> <td>1001</td> <td><img src="https://www.jb51.net/article/1.jpg" title="" alt="" /></td> <td>李小明</td> <td>男</td> <td>35.6元</td> </tr> <tr> <td><input type="checkbox" value="1" /></td> <td>1002</td> <td><img src="https://www.jb51.net/article/2.jpg" title="" alt="" /></td> <td>王明</td> <td>男</td> <td>28.9元</td> </tr> <tr> <td><input type="checkbox" value="2" /></td> <td>1003</td> <td><img src="https://www.jb51.net/article/3.jpg" title="" alt="" /></td> <td>皮特</td> <td>女</td> <td>34.3元</td> </tr> <tr> <td><input type="checkbox" value="3" /></td> <td>2356</td> <td><img src="https://www.jb51.net/article/4.jpg" title="" alt="" /></td> <td>爱丁堡</td> <td>男</td> <td>23.3元</td> </tr> </table> <table> <tr> <td> <span><input type="checkbox" />全选</span> <span><input type="button" value="删除" /></span> </td> </tr> </table> <img src="https://www.jb51.net/article/1.jpg" title="" alt="" /> </body> </html>