JS动态添加行

来源:互联网 发布:openstack用哪些数据库 编辑:程序博客网 时间:2024/05/21 09:59
这里只写了JS的实现语句,jsp部分根据id对应做就行,这里实现动态添加一行进行信息录入
<script type="text/javascript" language="javascript">function id(id){return document.getElementById(id);}var count = 1;function addRow(){<span style="white-space:pre"></span>var tableObj = id("testTable");<span style="white-space:pre"></span>var rowObj = tableObj.insertRow(-1);<span style="white-space:pre"></span>rowObj.setAttribute("id","newRow");<span style="white-space:pre"></span>var cellObj1 = rowObj.insertCell(-1);<span style="white-space:pre"></span>var cellObj2 = rowObj.insertCell(-1);<span style="white-space:pre"></span>var cellObj3 = rowObj.insertCell(-1);<span style="white-space:pre"></span>var cellObj4 = rowObj.insertCell(-1);<span style="white-space:pre"></span>var cellObj5 = rowObj.insertCell(-1);<span style="white-space:pre"></span>cellObj1.innerHTML = '<input type="text" name="e_id'+count+'" id="e_id'+count+'" onblur="show_etypename()" size="7"/>';<span style="white-space:pre"></span>cellObj2.innerHTML = '<input type="text" id="e_type'+count+'" onclick="showname()" size="14" disabled="disabled" />';<span style="white-space:pre"></span>cellObj3.innerHTML = '<input type="text" name="p_id'+count+'" id="p_id'+count+'" onblur="show_ptypename()" size="7"/>';<span style="white-space:pre"></span>cellObj4.innerHTML = '<input type="text" id="p_type'+count+'" onclick="showname()" size="14" disabled="disabled" />';<span style="white-space:pre"></span>cellObj5.innerHTML ='<input type="button" value="删除" onclick="delRow(1)"/>';<span style="white-space:pre"></span>count++;<span style="white-space:pre"></span>}function delRow(obj){<span style="white-space:pre"></span>var tableObj = id("testTable");<span style="white-space:pre"></span>if(1==obj){<span style="white-space:pre"></span>tableObj.deleteRow(-1);<span style="white-space:pre"></span>}}<span style="font-family: Arial, Helvetica, sans-serif;"></script></span>

0 0
原创粉丝点击