摘自:《jQuery权威指南》
1.在页面建立一个表格展现数据,各行变色
2.选中某行点击“删除”按钮能够删除该行,选中“全选”后点击“删除”按钮则删除所有数据
3.鼠标移到某行的小图片上,实现图片预览效果javascript
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>j_1_4.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <script type="text/javascript" src="../js/jquery-2.1.0.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: hand; } table tr td span { float: left; padding-left: 12px; } table tr th { background-color: #ccc; height: 32px; } .clsImg { position: absolute; border: solid 1px #ccc; padding: 3px; width: 150px; height: 200px; background-color: #eee; display: none; } .btn { border: solid 1px #666; padding: 2px; width: 50px; filter: progid:DXImageTransform.Microsoft .Gradient(GradientType=0,StartColorStr=#ffffff,EndColorStr=#ECE9D8); } </style> <script type="text/javascript"> $(function(){ $("table tr:nth-child(odd)").css("background-color", "#eee"); $("#chkAll").click(function(){ if(this.checked) { $("table tr td input[type=checkbox]").attr("checked", true); } else { $("table tr td input[type=checkbox]").attr("checked", false); } }); $("#btnDel").click(function(){ var intL = $("table tr td input:checked:not('#chkAll')").length; if(intL != 0) { $("table tr td input[type=checkbox]:not('#chkAll')").each(function(index){ if(this.checked) { $("table tr[id=" + this.value + "]").remove(); } }); } }); var x = 5; var y = 15; $("table tr td img").mousemove(function(e){ $("#imgTip").attr("src", this.src).css({"top":(e.pageY + y) + "px", "left":(e.pageX + x) + "px"}).show(300); }); $("table tr td img").mouseout(function(){ $("#imgTip").hide(); }); }); </script> </head> <body> <center> <table> <tr> <th>选项</th> <th>编号</th> <th>封面</th> <th>购书人</th> <th>性别</th> <th>购书价</th> </tr> <tr id="0"> <td><input id="Checkbox1" type="checkbox" value="0" /></td> <td>1001</td> <td><img src="Images/1.jpg"></td> <td>李小明</td> <td>男</td> <td>69.00元</td> </tr> <tr id="1"> <td><input id="Checkbox2" type="checkbox" value="1" /></td> <td>1002</td> <td><img src="Images/2.jpg"></td> <td>刘明明</td> <td>女</td> <td>108.00元</td> </tr> <tr id="2"> <td><input id="Checkbox3" type="checkbox" value="2" /></td> <td>1003</td> <td><img src="Images/3.jpg"></td> <td>刘芳芳</td> <td>女</td> <td>89.00元</td> </tr> </table> <table> <tr> <td style="text-align: left; height: 28px"> <span><input id="chkAll" type="checkbox" />全选</span> <span><input id="btnDel" type="button" value="删除" class="btn"/></span> </td> </tr> </table> <img id="imgTip" class="clsImg" src="Images/a5.gif"> </center> </body> </html>