javascript添加删除表行
2007-04-21 10:27
393 查看
<html>
<head>
<script language="javascript" id="clientEventHandlersJS0">
<!--
var tLinkmanNowRowIndex
var var_rowIndex
iNowRowIndex=-1
tLinkmanNowRowIndex=-1
var_rowIndex=0
function btnAddLinkman_onclick() {
var newRow = tLinkman.insertRow();
// newRow.bgColor='#efefef';
var newCell0 = newRow.insertCell();
newCell0.className='table_body';
newCell0.width = '40';
newCell0.align = 'center';
var iRowLength = tLinkman.rows.length;
newCell0.innerText = iRowLength - 1 ;
var newCell1 = newRow.insertCell();
newCell1.className='table_body';
// newCell1.width = '16%';
newCell1.innerHTML = "<input type=text class=textfield id=linkmanName" + (iRowLength-1) + " maxlength=5 size =20 title='最大5个中文字符'>";
var newCell2 = newRow.insertCell();
newCell2.className='table_body';
newCell2.width = '16%';
newCell2.innerHTML = "<input type=text class=textfield id=linkmanPhone" + (iRowLength-1) + " maxlength=13 size =30 title='格式:xxx-xxxxxxxx 或 xxxx-xxxxxxx'>";
}
function btnDelRow_onclick(tablename) {
var itemp
itemp =-1
if ((eval(tablename + "NowRowIndex") + 1)>1)
{
itemp = eval(tablename+"NowRowIndex")
}
else
{
itemp = eval(tablename).rows.length -1
}
if (itemp >0)
{
if (confirm("确定要" + event.srcElement.value + " " + itemp +" 吗?"))
{
eval(tablename).deleteRow(itemp)
for (i=1;i<eval(tablename).rows.length;i++)
eval(tablename).rows[i].cells[0].innerText = i
}
}
// if (tableName=="tLinkman")
tLinkmanNowRowIndex = -1
}
function getRow(e)
{
event.cancellBulle=true
var itemp;
var tableName
var iNowRowIndex
itemp=-1
tableName=""
iNowRowIndex = -1
if (event.srcElement.tagName.toLowerCase() == "td")
{
iNowRowIndex = event.srcElement.parentElement.rowIndex ;
tableName = event.srcElement.parentElement.parentElement.parentElement.id.toString()
}
if (event.srcElement.tagName.toLowerCase() == "input")
{
iNowRowIndex = event.srcElement.parentElement.parentElement.rowIndex;
tableName = event.srcElement.parentElement.parentElement.parentElement.parentElement.id.toString()
// alert(tableName)
}
itemp = eval(tableName + "NowRowIndex")
if (itemp > 0)
{
eval(tableName).rows[itemp].bgColor = '#ffffff';
eval(tableName).rows[itemp].cells[0].innerText = itemp
}
if(iNowRowIndex > -1)
{
if(iNowRowIndex > 0)
{
eval(tableName).rows[iNowRowIndex].cells[0].innerHTML = '<font color=blue>►</font>'
eval(tableName).rows[iNowRowIndex].bgColor = '#efefef'
}
if (tableName=="tLinkman")
tLinkmanNowRowIndex = iNowRowIndex
}
}
//-->
</script>
</head>
<body>
<input language="javascript" id="btnAddLinkman" onclick="btnAddLinkman_onclick()"
type="button" value="增加联系人" name="btnAddLinkman">
<input language="javascript" id="btnDelLinkman" onclick="btnDelRow_onclick('tLinkman')"
type="button" value="删除联系人">
<table class="table_all" id="tLinkman" cellspacing="0" cellpadding="0" width="100%"
align="left" border="1">
<tr>
<td class="table_second_title" align="left" width="45">
行号</td>
<td class="table_second_title" align="left" width="80">
姓名</td>
<td class="table_second_title" align="left" width="80">
联系电话</td>
</tr>
</table>
</body>
</html>
<script language="javascript" id="clientEventHandlersJS">
<!--
tLinkman.onclick = getRow;
//-->
</script>
<head>
<script language="javascript" id="clientEventHandlersJS0">
<!--
var tLinkmanNowRowIndex
var var_rowIndex
iNowRowIndex=-1
tLinkmanNowRowIndex=-1
var_rowIndex=0
function btnAddLinkman_onclick() {
var newRow = tLinkman.insertRow();
// newRow.bgColor='#efefef';
var newCell0 = newRow.insertCell();
newCell0.className='table_body';
newCell0.width = '40';
newCell0.align = 'center';
var iRowLength = tLinkman.rows.length;
newCell0.innerText = iRowLength - 1 ;
var newCell1 = newRow.insertCell();
newCell1.className='table_body';
// newCell1.width = '16%';
newCell1.innerHTML = "<input type=text class=textfield id=linkmanName" + (iRowLength-1) + " maxlength=5 size =20 title='最大5个中文字符'>";
var newCell2 = newRow.insertCell();
newCell2.className='table_body';
newCell2.width = '16%';
newCell2.innerHTML = "<input type=text class=textfield id=linkmanPhone" + (iRowLength-1) + " maxlength=13 size =30 title='格式:xxx-xxxxxxxx 或 xxxx-xxxxxxx'>";
}
function btnDelRow_onclick(tablename) {
var itemp
itemp =-1
if ((eval(tablename + "NowRowIndex") + 1)>1)
{
itemp = eval(tablename+"NowRowIndex")
}
else
{
itemp = eval(tablename).rows.length -1
}
if (itemp >0)
{
if (confirm("确定要" + event.srcElement.value + " " + itemp +" 吗?"))
{
eval(tablename).deleteRow(itemp)
for (i=1;i<eval(tablename).rows.length;i++)
eval(tablename).rows[i].cells[0].innerText = i
}
}
// if (tableName=="tLinkman")
tLinkmanNowRowIndex = -1
}
function getRow(e)
{
event.cancellBulle=true
var itemp;
var tableName
var iNowRowIndex
itemp=-1
tableName=""
iNowRowIndex = -1
if (event.srcElement.tagName.toLowerCase() == "td")
{
iNowRowIndex = event.srcElement.parentElement.rowIndex ;
tableName = event.srcElement.parentElement.parentElement.parentElement.id.toString()
}
if (event.srcElement.tagName.toLowerCase() == "input")
{
iNowRowIndex = event.srcElement.parentElement.parentElement.rowIndex;
tableName = event.srcElement.parentElement.parentElement.parentElement.parentElement.id.toString()
// alert(tableName)
}
itemp = eval(tableName + "NowRowIndex")
if (itemp > 0)
{
eval(tableName).rows[itemp].bgColor = '#ffffff';
eval(tableName).rows[itemp].cells[0].innerText = itemp
}
if(iNowRowIndex > -1)
{
if(iNowRowIndex > 0)
{
eval(tableName).rows[iNowRowIndex].cells[0].innerHTML = '<font color=blue>►</font>'
eval(tableName).rows[iNowRowIndex].bgColor = '#efefef'
}
if (tableName=="tLinkman")
tLinkmanNowRowIndex = iNowRowIndex
}
}
//-->
</script>
</head>
<body>
<input language="javascript" id="btnAddLinkman" onclick="btnAddLinkman_onclick()"
type="button" value="增加联系人" name="btnAddLinkman">
<input language="javascript" id="btnDelLinkman" onclick="btnDelRow_onclick('tLinkman')"
type="button" value="删除联系人">
<table class="table_all" id="tLinkman" cellspacing="0" cellpadding="0" width="100%"
align="left" border="1">
<tr>
<td class="table_second_title" align="left" width="45">
行号</td>
<td class="table_second_title" align="left" width="80">
姓名</td>
<td class="table_second_title" align="left" width="80">
联系电话</td>
</tr>
</table>
</body>
</html>
<script language="javascript" id="clientEventHandlersJS">
<!--
tLinkman.onclick = getRow;
//-->
</script>
相关文章推荐
- JavaScript实现跨浏览器的添加及删除事件绑定函数实例
- javaScript对Cookie的添加,获取,删除等操作
- 用javascript动态添加删除文本框
- JavaScript中对象属性的添加和删除示例
- javascript数组元素的添加、删除与插入以及参数数组的使用
- 解析javascript 数组以及json元素的添加删除
- <html5+css3+js>用javascript显示隐藏,添加,删除元素,css动画效果
- javascript动态添加、修改、删除对象的属性和方法
- javascript动态添加删除表格及克隆表格
- JavaScript操作Cookie的读取、添加、删除
- JavaScript通过代码添加删除事件
- javascript实现动态添加内容与删除内容
- Javascript 表单 Select 添加删除子项目
- javascript表格的添加和删除
- JavaScript动态添加删除表格行(支持FireFox)
- 在web下怎样用javascript向listbox中添加或删除所选定的项!
- JavaScript动态操作表格,添加,删除行、列及单元格
- javascript动态添加、修改、删除对象的属性和方法
- 学习笔记(JavaScript--动态添加上传域和删除上传域)
- JavaScript添加数组元素和删除数组元素