代码驿站移动版
频道导航
HTML/Xhtml
CSS
JavaScript
HTML5
PHP教程
ASP.NET
正则表达式
AJAX
ThinkPHP
Yii
MySQL
MariaDB
Oracle
MongoDB
Redis
DedeCMS
PHPCMS
帝国CMS
WordPress
Discuz
其它CMS
Zend Studio
Sublime
Notepad
Dreamweaver
Windows
Linux
Nginx
Apache
IIS
CentOS
Ubuntu
Debian
网站优化
工具资源
PHP源码
ASP.NET源码
其它源码
图标素材
按钮素材
字体素材
DedeCMS模板
帝国CMS模板
PHPCMS模板
WordPress模板
Discuz!模板
单页模板
开发软件下载
服务器软件下载
广告投放
联系我们
版权申明
软件编程
网页前端
移动开发
数据库
服务器
脚本语言
PHP代码
JAVA代码
Python代码
Android代码
当前位置:
主页
>
网页前端
>
JavaScript代码
>
js下为表格内部动态添加行的代码
时间:2021-02-24 09:35:32 | 栏目:
JavaScript代码
| 点击:次
未添加行之前:
添加行之后:
演示代码:
<!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> <title>给表格内部动态添加行</title> <style type="text/css"> .tableStyle { border-collapse: collapse; width:100%; } td { font-size:12px; height:25px; border:1px solid #CCD5E8; } .btn { font-size:12pt; color: #003399; border: 1px #003399 solid; color:#006699; border-bottom: #93bee2 1px solid; border-left: #93bee2 1px solid; border-right: #93bee2 1px solid; border-top: #93bee2 1px solid; background-color: #e8f4ff; cursor: pointer; font-style: normal ; width:20px; height:22px; font-family:Verdana;font-family:Georgia;_font-family:Tahoma; padding:0 10px 1px;padding:3px 3px 1px;_padding:0 4px 1px; line-height:18px;line-height:14px;_line-height:16px; } </style> </head> <body> <table class="tableStyle" id="OwnershipStructure"> <tr> <td width="15%" rowspan="2" id="StructureLeft1"> 标的企业 股权结构 </td> <td width="15%" rowspan="2" id="StructureLeft2">股东人数:人 </td> <td width="30%"> 前十名出资人的名称<strong>(做成动态,填几个显示几个)</strong> </td> <td width="30%">出资比例 </td> </tr> <tr id="StructureRight"> <td> <input id="Text1" type="text" /></td> <td> <input id="Text2" type="text" /><input id="btnAddRow" class="btn" onclick="AddStructureRow()" type="button" value="+" /> </td> </tr> <tr> <td>评估机构</td><td></td><td></td><td></td> </tr> <tr><td>评估机构</td><td></td><td></td><td></td> </tr> </table> <script language="javascript" type="text/javascript"> //表单操作 function AddStructureRow() { var obj=document.getElementById("OwnershipStructure"); var tr= obj.rows["StructureRight"]; //alert(tr.rowIndex); var count=document.getElementById("StructureLeft1").getAttribute("rowspan"); document.getElementById("StructureLeft1").setAttribute("rowSpan",parseInt(count)+1); document.getElementById("StructureLeft2").setAttribute("rowSpan",parseInt(count)+1); //插入行 code form www.jb51 .net var tr =obj.insertRow(tr.rowIndex+1); var trId="trStructure"+tr.rowIndex; tr.setAttribute("id",trId); var td0 = tr.insertCell(0); td0.setAttribute("align","left"); //td0.setAttribute("colSpan","4"); td0.innerHTML = "<input ID='txtName' type='text'/> "; var td1 = tr.insertCell(1); td1.setAttribute("align","left"); //td1.setAttribute("colSpan","3"); td1.innerHTML = "<input ID='txtName' type='text'/><input id='btnDelRow' class='btn' type='button' value='-' onclick='DelStructureRow("+tr.rowIndex+")'/>"; } function DelStructureRow(rowIndex) { var obj=document.getElementById("OwnershipStructure"); obj.deleteRow(rowIndex); var count=document.getElementById("StructureLeft1").getAttribute("rowspan"); document.getElementById("StructureLeft1").setAttribute("rowSpan",parseInt(count)-1); //rowSpan 不要写成rowspan,因为在IE6 与IE7下会有问题 document.getElementById("StructureLeft2").setAttribute("rowSpan",parseInt(count)-1); } //End---股东出资人表单操作 </script> </body> </html>
[Ctrl+A 全选 注:
引入外部Js需再刷新一下页面才能执行
]
您可能感兴趣的文章:
JavaScript常见事件处理程序实例总结
Javascript的匿名函数小结
url传递的参数值中包含&时,url自动截断问题的解决方法
javascript上下左右定时滚动插件
Javascript别踩白块儿(钢琴块儿)小游戏实现代码
相关文章
11-08
兼容浏览器的js事件绑定函数(详解)
11-23
Webpack中loader打包各种文件的方法实例
11-27
Javascript实例教程(19) 使用HoTMetal(2)
10-05
javascript判断图片是否加载完成的方法推荐
11-22
在javascript中执行任意html代码的方法示例解读
JQuery
VUE
AngularJS
MSSql
MySQL
MongoDB
Redis
Linux
Tomcat
Nginx
网站首页
广告投放
联系我们
版权申明
联系站长