JS :点击按钮table增加一行,删除一行
2012-04-18 19:37
645 查看
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>update_data.jsp</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" href="<%=path%>/css/data_text.css" type="text/css" /> <link rel="stylesheet" type="text/css" href="styles.css"> --> <script type="text/javascript"> //给table增加一行 function addTableRow() { var table1 = document.getElementById('table1'); var cloneTab = document.getElementById('table2'); //alert(cloneTab.firstChild.firstChild.innerHTML); //alert(cloneTab.firstChild.firstChild.cloneNode(true).innerHTML); table1.firstChild.appendChild(cloneTab.firstChild.firstChild.cloneNode(true)); var v= table1.firstChild.childNodes; var len = v.length; for(var i=1;i<len;i++){ v[i].childNodes[0].firstChild.id=i;//给第一个单元格id赋值 } } //给table删除一行 function delTableRow(){ var table1 = document.getElementById('table1'); var isChecked = document.getElementsByName('isChecked'); var len = isChecked.length; for(var i=len-1;i>=0;i--){ if(isChecked[i].checked==true){ table1.firstChild.removeChild(isChecked[i].parentNode.parentNode); //alert(isChecked[i].id); //alert(isChecked[i].parentNode.parentNode.innerHTML); } } } </script> </head> <body> <table border="0" cellpadding="0" cellspacing="0" class="datalist" id="table1"> <tr> <th width="38" nowrap="nowrap" style="width: 5%">0</th> <th width="38" nowrap="nowrap" >00</th> <th width="79" nowrap="nowrap" scope="col">1</th> <th width="70" nowrap="nowrap" scope="col">2</th> <th width="69" nowrap="nowrap" scope="col">3</th> <th width="66" nowrap="nowrap" scope="col">4</th> <th width="94" nowrap="nowrap" scope="col">5</th> <th width="107" nowrap="nowrap" scope="col">6</th> </tr> </table> <!--控制table的按钮--> <table> <tr align="center"> <td colspan="10"> <input type="button" value="增加" onclick= "addTableRow();"/> <input type="button" value="删除" onclick="delTableRow();"/> </td> </tr> </table> <!--模板table也叫做clone table style = "display:none"--> <table id='table2' style="display: none"> <tr> <th><input type="checkbox" name="isChecked" /><input type="hidden" size="6" value=""/></th> <th width="38" nowrap="nowrap" style="width: 5%"><input type="text" size="16" maxlength="50" value=""/></th> <th width="79" nowrap="nowrap" scope="col"><input type="text" size="16" maxlength="50" value=""/></th> <th width="70" nowrap="nowrap" scope="col"><input type="text" size="6" maxlength="10" value=""/></th> <th width="69" nowrap="nowrap" scope="col"> <select size="1"> <option value="">请选择...</option> <option value="1">1</option> <option value="2">1</option> </select> </th> <td width="100" nowrap="nowrap" scope="col"><input type="text" class="date150"/></td> <th width="94" nowrap="nowrap" scope="col"><input type="text" size="16" maxlength="50" value=""/></th> <th width="71" nowrap="nowrap" scope="col"><input type="text" size="16" maxlength="50" value=""/></th> </tr> </table> </body> </html>
相关文章推荐
- js点击按钮删除一行并传递参数小结1
- 支持所有浏览器,通过JS为 Table表增加、删除一行
- 在后台 如何实现 按钮点击后 Table能动态增加一行
- 利用js对table动态增加和删除行(附带table样式,鼠标滑过和点击样式)
- 在后台 如何实现 按钮点击后 Table能动态增加一行
- 动态表格,通过点击按钮增加或者删除一行表格!
- 通过JS为 Table表增加一行,通过复选框删除多行,也可通过所在行的delete链接删除本行
- 点击按钮,表格增加/删除一行
- JS点击按钮自动增加一行 4000
- 动态的把数据显示在table中,点击某一行的删除按钮实现该行的删除(通过ajax实现页面的无刷新加载)
- SpringMVC批量插入,js点击按钮自动增加一行
- 动态的把数据显示在table中,点击某一行的删除按钮实现该行的删除(通过ajax实现页面的无刷新加载)
- 在可编辑表格EditorGrid中,我选择一行已输入的数据,点击删除按钮,该行数据将被删除,然后当我点击表单提交按钮时,已经被删除的那一行数据仍然被插入数据库中
- JQuery实现动态表格点击按钮表格增加一行
- cocos2d js 给sprite增加按钮点击事件
- 利用js实现table增加一行
- 常用的js动态增加(删除)table数据行的功能
- js操作table(增加行,删除行,上移,下移,复制行)
- 在可编辑表格EditorGrid中,我选择一行已输入的数据,点击删除按钮,该行数据将被删除,然后当我点击表单提交按钮时,已经被删除的那一行数据仍然被插入数据库中