脚本给TABLE 添加 删除 行的操作DEMO

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
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>My JSP 'index.jsp' starting page</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" type="text/css" href="styles.css">
	-->
	
	
	<script>
//给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>
   
    <div>
				<div style="float: left; WIDTH: 99%; position: relative;">
		    <table id="table1" width="99%" cellspacing="1" cellpadding="1" border="0" bgcolor="#336699" align="left" style="margin-top:10px;">
              <tr bgcolor="#6699CC" align="center"
												style="font-weight: bold;">
												<td class="pt12-wh" width="10%" height="25">
													选择
												</td>
												<td class="pt12-wh" width="15%" height="25">
													检测
												</td>
												<td class="pt12-wh" width="15%" height="25">
												    容限/范围
												</td>
												<td class="pt12-wh" width="20%" height="25">
													检测方法
												</td>
												<td class="pt12-wh" width="20%" height="25">
												检查部门
												</td>
												<td class="pt12-wh" width="10%" height="25">
													频率
												</td>
												<td class="pt12-wh" width="10%" height="25">
													结果
												</td>
											</tr>
            
             </table>
             
             </div>
             </div>
              <!--控制table的按钮-->
             <div style="width: 99%; text-align: right; margin-top: 10px; margin-bottom: 2px; float: left">
					 <input type="button"  value="增加" οnclick= "addTableRow();"/> 
                     <input type="button"  value="删除" οnclick="delTableRow();"/>
                     
                     <!--模板table也叫做clone table style = "display:none"-->
  <table id='table2' style="display: none">
  <tr>
    <th  bgcolor="white" class="pt12-black" align="center"><input type="checkbox" name="isChecked" /><input type="hidden" size="6" value=""/></th>
    <th  nowrap="nowrap"  bgcolor="white" class="pt12-black" align="center"><input name="detection" type="text"  /></th>
    <th  nowrap="nowrap"  bgcolor="white" class="pt12-black" align="center"><input name="scope" type="text"  /></th>
    <th  nowrap="nowrap"  bgcolor="white" class="pt12-black" align="center"><input name="detectmethod" type="text"  /></th>
    <th  nowrap="nowrap"  bgcolor="white" class="pt12-black" align="center"><input name="inspectiondepart" type="text"  /></th>
    <th  nowrap="nowrap"  bgcolor="white" class="pt12-black" align="center"><input name="rate" type="text"  size="10"/></th>
    <th  nowrap="nowrap"  bgcolor="white" class="pt12-black" align="center"><select size="1" id="inspectresult" name="inspectresult">
              <option value="合格">合格</option>
              <option value="不合格">不合格</option>
         </select></th>
   
  </tr>
  </table>
                     
                     
				</div>
  </body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Bootstrap Table是一个基于Bootstrap的表格插件,它提供了一套简单易用的表格展示和操作功能。 要实现Bootstrap Table的分页功能,可以通过以下步骤: 1. 首先,在HTML文件中引入必要的样式表和脚本文件,包括Bootstrap的CSS和JS文件、Bootstrap Table的CSS和JS文件以及相关的插件文件。 2. 在HTML文件中创建一个表格元素,并给它一个唯一的id属性,用来标识这个表格。 3. 在JavaScript文件中编写相应的代码,在页面加载完成后初始化Bootstrap Table,并设置一些基本的参数,如表格的id、数据源等。示例如下: ```javascript $(document).ready(function() { // 初始化Bootstrap Table $('#table-demo').bootstrapTable({ url: 'data.json', // 数据源文件的URL pagination: true, // 启用分页功能 pageSize: 10, // 每页显示的记录数 pageList: [10, 25, 50, 100], // 可选择的每页记录数 paginationPreText: '<', // 上一页按钮的图标或文字 paginationNextText: '>', // 下一页按钮的图标或文字 paginationLoop: false, // 禁止循环翻页 sidePagination: 'client', // 客户端分页 columns: [{ field: 'id', title: 'ID' }, { field: 'name', title: '名称' }, { field: 'age', title: '年龄' }] }); }); ``` 4. 在数据源文件中提供需要显示的数据,如JSON格式的数据。在上述代码中,数据源文件为data.json,可以根据实际情况修改。 通过以上步骤,就可以实现一个简单的Bootstrap Table分页的demo。可以根据实际需求修改和扩展代码,实现更多的功能和样式定制。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值