有如下代码,想在动态添加一行后,在每一行后面 出现删除按钮,点击这个按钮可以删除该行。麻烦将代码修改一下。谢谢!新手,见谅!<html>
<TABLE border="0" width="50%" id="activeTable1"></TABLE>
<p>
<input type="button" name="Submit3" value=" 增 加 备 件 " onclick="AddRecord1()" >
<script> function getback(obj)
{
var td = obj.parentNode;
var dangjia = td.previousSibling.firstChild;
var shuliang = td.previousSibling.previousSibling.firstChild;
obj.value = (shuliang.value * dangjia.value).toFixed(2);
}
function AddRecord1()
{
var row = activeTable1.insertRow(activeTable1.rows.length);//id=recordTable
var col = row.insertCell(0);
var i = row.rowIndex;
col.innerHTML = "<input type='text' name='texth' value=''>";
col = row.insertCell(1);
col.innerHTML = "<input type='text' name='texti' value=''>";
col = row.insertCell(2);
col.innerHTML = "<input type='text' name='textj' value=''>";
col = row.insertCell(3);
col.innerHTML = "<input type='text' name='textk' onClick='getback(this)'; value=''>";
col = row.insertCell(4);
col.innerHTML = "<input type='hidden' name='textl' value='"+i+ "'>";
}
</script></html>
<TABLE border="0" width="50%" id="activeTable1"></TABLE>
<p>
<input type="button" name="Submit3" value=" 增 加 备 件 " onclick="AddRecord1()" >
<script> function getback(obj)
{
var td = obj.parentNode;
var dangjia = td.previousSibling.firstChild;
var shuliang = td.previousSibling.previousSibling.firstChild;
obj.value = (shuliang.value * dangjia.value).toFixed(2);
}
function AddRecord1()
{
var row = activeTable1.insertRow(activeTable1.rows.length);//id=recordTable
var col = row.insertCell(0);
var i = row.rowIndex;
col.innerHTML = "<input type='text' name='texth' value=''>";
col = row.insertCell(1);
col.innerHTML = "<input type='text' name='texti' value=''>";
col = row.insertCell(2);
col.innerHTML = "<input type='text' name='textj' value=''>";
col = row.insertCell(3);
col.innerHTML = "<input type='text' name='textk' onClick='getback(this)'; value=''>";
col = row.insertCell(4);
col.innerHTML = "<input type='hidden' name='textl' value='"+i+ "'>";
}
</script></html>
解决方案 »
- js怎样实现自己的电脑在某个时间点自动关机
- js 弹出框(提交页面后不关闭)
- 用js如何读取两标签数据
- 小弟有两个问题还不明白,请各位大虾帮忙解答下,谢谢
- 谁来管管啊,CSDN的帖子管理的脚本有错误!
- javascript 一个字符相连,高手进入呀
- 求一些文章,关于javascript兼容多种浏览器的问题.给地址也行,回贴写一些内容也行,只要有用都给分,可再开贴给分.
- 如何在JS里加声音效果
- 大家来解密~~~
- 您今天看帖子了吗?
- 遍历复选框 如果一个都没选中就不提交表单!
- 有办法将<li><a href="/">首页</a></li> <li > <a href="/">1</a></li>变成字符串
<html>
<TABLE border="0" width="50%" id="activeTable1"></TABLE>
<p>
<input type="button" name="Submit3" value=" 增 加 备 件 " onclick="AddRecord1()" >
<script> function getback(obj)
{
var td = obj.parentNode;
var dangjia = td.previousSibling.firstChild;
var shuliang = td.previousSibling.previousSibling.firstChild;
obj.value = (shuliang.value * dangjia.value).toFixed(2);
}
function delRow(btn){
var tr = btn.parentNode.parentNode;
tr.parentNode.removeChild(tr);
}
function AddRecord1()
{
var row = activeTable1.insertRow(activeTable1.rows.length);//id=recordTable
var col = row.insertCell(0);
var i = row.rowIndex;
col.innerHTML = "<input type='text' name='texth' value=''>";
col = row.insertCell(1);
col.innerHTML = "<input type='text' name='texti' value=''>";
col = row.insertCell(2);
col.innerHTML = "<input type='text' name='textj' value=''>";
col = row.insertCell(3);
col.innerHTML = "<input type='text' name='textk' onClick='getback(this)'; value=''>";
col = row.insertCell(4);
col.innerHTML = "<input type='hidden' name='textl' value='"+i+ "'><input type='button' value='删除' onclick='delRow(this)' />";
}
</script></html>
<TABLE border="0" width="50%" id="activeTable1"></TABLE>
<p>
<input type="button" name="Submit3" value=" 增 加 Y 件 " onclick="AddRecord1()" >
<script>function getback(obj)
{
var td = obj.parentNode;
var dangjia = td.previousSibling.firstChild;
var shuliang = td.previousSibling.previousSibling.firstChild;
obj.value = (shuliang.value * dangjia.value).toFixed(2);
}
function AddRecord1()
{
var row = activeTable1.insertRow(activeTable1.rows.length);//id=recordTable
var col = row.insertCell(0);
var i = row.rowIndex;
col.innerHTML = "<input type='text' name='texth' value=''>";
col = row.insertCell(1);
col.innerHTML = "<input type='text' name='texti' value=''>";
col = row.insertCell(2);
col.innerHTML = "<input type='text' name='textj' value=''>";
col = row.insertCell(3);
col.innerHTML = "<input type='text' name='textk' onClick='getback(this);' value=''>";
col = row.insertCell(4);
col.innerHTML = "<input type='hidden' name='textl' value='"+i+ "'>";
col = row.insertCell(5);
col.innerHTML = "<input type='button' name='btn1' onClick='del(this.parentNode.parentNode);' value='del' >";
}
function del(o){
activeTable1.childNodes[0].removeChild(o);
}
</script></html>