Jquery-1实现简单的复选框删除增加操作
2016-06-07 17:55
746 查看
1.实现简单的复选框删除增加操作
<pre name="code" class="html"><!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>简单的复选框删除增加操作</title>
/<span style="font-size:18px;color:#ff0000;">/引用的是jquery-2.2.4.js版本 <script src="js/jquery-2.2.4.js"></script></span> <script> $(function(){ $("input[type=checkbox]:eq(0)").change(function(){ var checkvalue=$(this).prop("checked"); <span style="font-size:24px;color:#ff0000;">//not(0)表示不选第一行操作栏</span> $("input[type=checkbox]:not(0)").prop("checked",checkvalue); if($(this).prop("checked")){ $("input[type=checkbox]:not(0)").prop("checked","true"); }else{ $("input[type=checkbox]:not(0)").prop("checked",""); } }); //单条删除 $("td a").click(function(){ //提示框 if(confirm("你确定真的要删除嘛")){ $(this).parent("td").parent("tr").remove(); } }); //选择框选定的才删除 $("input[value='删除']").click(function(){ //提示框 if(confirm("你确定真的要删除嘛")) { $("input[type='checkbox']:not(:first):checked").parent("td").parent("tr").remove(); } }); $("input[value='增加']").click(function(){ //进行字符串拼接 var strShopInfo="<tr>"+ "<td><input type=\"checkbox\"/></td>"+ "<td>张四</td>"+ "<td>1222211111</td>"+ "<td><a href=\"#\" onclick='deleteItem(this)'>删除</a></td>"+ "</tr>"; $("#myTableProduct tbody").append(strShopInfo); }); }); <span style="font-size:32px;color:#ff0000;">//新定义一个方法以便让增加后数据也能删除,关键点</span> function deleteItem(obj){ //提示框 if(confirm("确定要删除嘛")) { $(obj).parent("td").parent("tr").remove(); } } </script> </head> <body> <table border="1px" cellspacing="0px" id="myTableProduct"> <tr> <td><input type="checkbox" />全选</td> <td>用户名</td> <td>电话号码</td> <td>操作</td> </tr> <tr> <td><input type="checkbox"/></td> <td>张三</td> <td>1222211111</td> <td><a href="#">删除</a></td> </tr> <tr> <td><input type="checkbox"/></td> <td>张四</td> <td>1222211111</td> <td><a href="#">删除</a></td> </tr> <tr> <td><input type="checkbox"/></td> <td>张五</td> <td>1222211111</td> <td><a href="#">删除</a></td> </tr> </table> <input type="button" value="增加"/> <input type="button" value="删除"/> </body> </html>
相关文章推荐
- jquery实现滚动到页面底部时无限加载内容的代码
- jquery控制复选框
- jquery为多个元素添加事件
- 11个好用的jQuery拖拽拖放插件
- [转]Hide or Remove jquery ui tab based on condition
- jQuery获取表格中一行的值和获取重复ID的值
- jquery给easyui-window的title赋值
- jquery实现返回顶部、底部功能
- 基于jQuery下拉选择框插件支持单选多选功能代码
- jQuery原理系列-css选择器的简单实现
- jQuery offset,position,offsetParent,scrollLeft,scrollTop html控件定位 css position
- jQuery深入之源码解析(四)——分离构造器
- web前端复习(一):jquery实现轮播
- jQuery 如何先创建、再修改、后添加DOM元素
- jQuery.Autocomplete实现自动完成参数详解
- jQuery原理系列-常用Dom操作详解
- 浅谈jQuery 选择器和dom操作
- DOM操作和jQuery实现选项移动操作的简单实例
- 基于jQuery下拉选择框插件支持单选多选
- jQuery 数据 - jQuery.data() 方法