JS动态添加行列

摘要:
0&&parent.frames.length){theDoc=parent.frames[theObj.substring(p+1)].document;theObj=theObj.substring(0,p);}if(!(foundObj=theDoc[theObj])&&theDoc.all)foundObj=theDoc.all[theObj];for(i=0;!foundObj&&i˂theDoc.forms.length;i++)foundObj=theDoc.forms[i][theObj];for(i=0;!
JS动态添加行列第1张JS动态添加行列第2张
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Add-Delete Row.aspx.cs" Inherits="Add_Delete_Row" %>

<!DOCTYPE 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 runat="server">
    <title></title>
    <style type="text/css">#Add{ margin:0px auto;}
        #tab{ border-collapse:collapse; text-align:center; margin:0auto;}
        #tab td{ border:1px solid #000000;}
        #tr1{ font-family:@华文仿宋; color:Red;}
    </style>
    <script type="text/javascript">function findObj(theObj, theDoc) {
            varp, i, foundObj;
            if (!theDoc) theDoc =document;
            if ((p = theObj.indexOf("?")) > 0 &&parent.frames.length)
            { theDoc = parent.frames[theObj.substring(p + 1)].document; theObj = theObj.substring(0, p); } if (!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj]; for (i = 0; !foundObj && i < theDoc.forms.length; i++) foundObj = theDoc.forms[i][theObj]; for (i = 0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) foundObj = findObj(theObj, theDoc.layers[i].document); if (!foundObj && document.getElementById) foundObj = document.getElementById(theObj); returnfoundObj;
        }
        function addRow() {
            //读取添加一行的行号,存放在txtIndex文本框中 
            var txtIndex = findObj("txtIndex", document);
            var rowID =parseInt(txtIndex.value);
            //alert(rowID);
            //添加一行
            var signFrame = findObj("tab", document);
            //添加行
            var newTR =signFrame.insertRow(signFrame.rows.length);
            newTR.id = "SignItem" + rowID; //添加行数的ID
           
            //添加列
            var NewTd1 = newTR.insertCell(0);
            NewTd1.style.width = 200;
            var NewTd2 = newTR.insertCell(1); 
            NewTd2.style.width = 190;
            var NewTd3 = newTR.insertCell(2);
            NewTd3.style.width = 210;
            var NewTd4 = newTR.insertCell(3);
            NewTd4.style.width = 40;
            //设置列的内容及属性
            NewTd1.innerHTML = "<input type = 'text'   id = 'txt " + rowID + "' />";
            NewTd2.innerHTML = "<input type = 'text'   id = 'txt " + rowID + "' />";
            NewTd3.innerHTML = "<input type = 'text'   id = 'txt " + rowID + "' />";
            NewTd4.innerHTML = "<a   href = 'https://tool.4xseo.com/article/55172.html' onclick = "DeleteSignRow('SignItem" + rowID + "')">删除</a>";            
            //将行号推进到下一行
            txtIndex.value = (rowID + 1).toString();
        }
        //删除指定行
function DeleteSignRow(rowid) {
            var signFrame = findObj("tab", document);
            var signItem =findObj(rowid, document);

            //获取将要删除的行的Index
            var rowIndex =signItem.rowIndex;
            //alert(rowIndex);
            //删除指定Index的行
signFrame.deleteRow(rowIndex);

            //重新排列序号,如果没有序号,这一步省略
//for (i = rowIndex; i < signFrame.rows.length; i++) {
//signFrame.rows[i].cells[0].innerHTML = i.toString();
//}
}
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div style = "640px; margin:0 auto;" id = "dv">
    <input type="button" id="Add" value="添加一行" onclick = "addRow()" />
        <input name='txtIndex' type='hidden' id='txtIndex' value="4" />
    <br />
    </div>
    <table width = "640" cellpadding="0" cellspacing="0" id = "tab">
        <tr>
            <td>姓名
            </td>
            <td colspan = "3">
                
            </td>
        </tr>
        <tr id = "tr1">
            <td style = "200px;">姓名</td>
            <td style = "190px">邮箱</td>
            <td style = "210px">投标内容</td>
            <td style = "40px"></td>
        </tr>
        <tr>
            <td>性别</td>
            <td colspan = "3">
                
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
View Code

免责声明:文章转载自《JS动态添加行列》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇C语言文件读写操作总结Delphi 条件编译语法 $IFDEF $ELSE $ENDIF下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

更新js缓存办法

http://zhenggm.iteye.com/blog/680600 遇到的问题:在访问量比较大的系统中,我们需要将一些静态的文件在客户端缓存,以减少下载的流量,从而加快客户端访问的速度。但是缓存会带来一个问题,就是如何在服务端更新完文件之后,客户端能够及时得到更新。 解决思路:1. 在一个配置文件中维护js文件map; 2. 在页面中通过js ma...

BUI 框架使用指南

  指南说明:只适用于对框架的剥离 如果不需要剥离则原来的东西直接粘贴就行  在主界面中使用时需要加入一下引用bui.js jquery.js config.js 末尾的文件 BUI.use(位置1, function ()  其中位置一需要填写你的main-min.js 文件所在的路径以及main的文件名 例如我的文件在Resouce/JS/main-...

phpcms常用接口调用方法

常用函数 , 打开include/global.func.php,下面存放一些公共函数 view plaincopy to clipboardprint?function str_charset($in_charset, $out_charset, $str_or_arr) //转换字符串或者数组的编码function set_cookie($var, $...

Ext Js简单Grid创建使用及AJAX处理

在使用Ext Js对于Grid组件使用必不可少的,对于它的掌握也是需要的。简单贴一些代码,看看Grid的创建使用,就不细讲每一步了,代码注释还可以,不明白的可以在评论中写一下,或发邮件给我,一定帮助解答,欢迎交流。1.简单Ext JsGrid的创建使用(创建Ext.grid.GridPanel需要store(proxy\reader)\colModel)...

angularjs 路由 异步加载js

angularjs 异步加载js 有两种方法 第一种 使用$q 和 requireJS 加载 这个问题 首要出现 在 当我 把require 引入 项目中是,希望做到 点击路由时加载相应的页面html和 js. 起初我是将 route 的 controller 设置为 require(‘controller.js’) 来 异步加载, 当然,问题是不可能这么...

JS阻止默认行为

如果事件可取消,则取消该事件,而不停止事件的进一步传播。 语法 event.preventDefault(); 案例 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>ev...