jQuery全選全刪動態表格

jQuery全選全刪動態表格

1.效果圖附上:
在這裏插入圖片描述

2.代碼呈上:



<!DOCTaYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<meta name="keywords" content=" keywords" />
<meta name="description" content="description" />
</head>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></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 id="0">
<td><input type="checkbox" name="" id="checkbox1" value="0" /></td>
<td>1001</td>
<td><img src="img/1.jpg" title="" alt="" class="a" /></td>
<td>真三風</td>
<td></td>
<td>35.6</td>
</tr>
<tr id="1">
<td><input type="checkbox" name="" id="checkbox2" value="1" /></td>
<td>1002</td>
<td><img src="img/2.jpg.png" title="" alt="" class="a" /></td>
<td>張三丰</td>
<td></td>
<td>28.9</td>
</tr>
<tr id="2">
<td><input type="checkbox" name="" id="checkbox3" value="2" /></td>
<td>1003</td>
<td><img src="img/3.jpg.png" title="" alt="" class="a" /></td>
<td>賈三瘋</td>
<td></td>
<td>34.3</td>
</tr>
<tr id="3">
<td><input type="checkbox" name="" id="checkbox3" value="3" /></td>
<td>2356</td>
<td><img src="4.jpg" title="" alt="" class="a" /></td>
<td>三豐</td>
<td></td>
<td>23.3</td>
</tr>
</table>
<table>
<tr>
<td style="text-align:left;height:28px">
<span><input type="checkbox" name="" id="checkAll" />全選</span>
<span><input type="button" value="刪除" class="btn" /></span>
</td>
</tr>
</table>
<img src="img/2.jpg.png" title="" alt="" id="imgTip" class="clsImg" />
</body>
</html>



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章