<html>
<head>
<script language="JavaScript"><!--
function addRow() {
var tableObj = document.getElementById("mainTb");
var newRowObj = tableObj.insertRow(tableObj.rows.length); var newNameCell = newRowObj.insertCell(newRowObj.cells.length);
var newCompanyCell = newRowObj.insertCell(newRowObj.cells.length);
var newButtonCell = newRowObj.insertCell(newRowObj.cells.length); newNameCell.innerHTML = document.getElementById("newName").value;
newCompanyCell.innerHTML = document.getElementById("newCompany").value;
newButtonCell.innerHTML = '<input type="button" value="删除" onclick="deleteRow('+(tableObj.rows.length-1)+')">';
}
function deleteRow(index) {
var tableObj = document.getElementById("mainTb");
tableObj.deleteRow(index);
}
--> </script>
</head>
<body style="margin:40px">
<div><span id="new">姓名<input type="text" name="newName" id="newName">单位<input type="text" id="newCompany"><input type="button" value="新增" onclick="addRow()"></span></div>
<table id="mainTb" border="1">
<tr><th width="80">姓名</th><th width="250">单位</th></tr>
<tr id="row0"><td>张三</td><td>北京欣光软件公司</td><td><input type="button" value="删除" onclick="deleteRow(1)"></td></tr>
<tr id="row1"><td>李四</td><td>上海南市食品公司</td><td><input type="button" value="删除" onclick="deleteRow(2)"></td></tr>
</table>
</body>
</html>
---------------------------------------------------------------------
意愿:
我删除任意一行时~`
不会造成错误~`
现在的问题时~
当你添加两条或者更多时``
如有四条``
你先删除第三行~
再删除第四条行时``
就会提示:参数无效的`红色部分的惑问``
为什么要加单引号的~`
数字也要引号`
那不成了字符串了吗/``
<head>
<script language="JavaScript"><!--
function addRow() {
var tableObj = document.getElementById("mainTb");
var newRowObj = tableObj.insertRow(tableObj.rows.length); var newNameCell = newRowObj.insertCell(newRowObj.cells.length);
var newCompanyCell = newRowObj.insertCell(newRowObj.cells.length);
var newButtonCell = newRowObj.insertCell(newRowObj.cells.length); newNameCell.innerHTML = document.getElementById("newName").value;
newCompanyCell.innerHTML = document.getElementById("newCompany").value;
newButtonCell.innerHTML = '<input type="button" value="删除" onclick="deleteRow('+(tableObj.rows.length-1)+')">';
}
function deleteRow(index) {
var tableObj = document.getElementById("mainTb");
tableObj.deleteRow(index);
}
--> </script>
</head>
<body style="margin:40px">
<div><span id="new">姓名<input type="text" name="newName" id="newName">单位<input type="text" id="newCompany"><input type="button" value="新增" onclick="addRow()"></span></div>
<table id="mainTb" border="1">
<tr><th width="80">姓名</th><th width="250">单位</th></tr>
<tr id="row0"><td>张三</td><td>北京欣光软件公司</td><td><input type="button" value="删除" onclick="deleteRow(1)"></td></tr>
<tr id="row1"><td>李四</td><td>上海南市食品公司</td><td><input type="button" value="删除" onclick="deleteRow(2)"></td></tr>
</table>
</body>
</html>
---------------------------------------------------------------------
意愿:
我删除任意一行时~`
不会造成错误~`
现在的问题时~
当你添加两条或者更多时``
如有四条``
你先删除第三行~
再删除第四条行时``
就会提示:参数无效的`红色部分的惑问``
为什么要加单引号的~`
数字也要引号`
那不成了字符串了吗/``
解决方案 »
- 大神,判断正则表达式 多选题!!!!!!
- jqery中onclick="fun()"中的$(this)是什么
- IE6下出错,firefox没问题:Expected identifier, string or number
- 下拉列表框实现页面跳转时为什么不能在同一窗口
- 借地儿,问个关于ActionScript组件的问题
- 如何判断checkbox至少选择一项
- 有关日期对象date的问题,见内
- 如何在文本框内输入小写金额,自动显示出带分隔符的金额?
- 那位大侠给提供一下这个JavaScript的网页实列!
- 如何实现父窗刷新一个子窗的动作呢?
- js Dom,appendChild的问题,用outterHTML可以实现
- 用javascript在网页上显示时间的问题
删除行时~
同时要更改索引的呢?`