js动态增加、删除行

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>MyHtml.html</title>

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function rowindex(tr)
{
var Browser = new Object();

Browser.isMozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument != 'undefined');
Browser.isIE = window.ActiveXObject ? true : false;
Browser.isFirefox = (navigator.userAgent.toLowerCase().indexOf("firefox") != - 1);
Browser.isSafari = (navigator.userAgent.toLowerCase().indexOf("safari") != - 1);
Browser.isOpera = (navigator.userAgent.toLowerCase().indexOf("opera") != - 1);
if (Browser.isIE)
{
return tr.rowIndex;
}
else
{
table = tr.parentNode.parentNode;
for (i = 0; i < table.rows.length; i ++ )
{
if (table.rows[i] == tr)
{
return i;
}
}
}
}

/**
* 新增一个价格阶梯
*/
function addLadder(obj)
{

var src = obj.parentNode.parentNode;

var idx = rowindex(src);
var tbl = document.getElementById("groupTable");
var row = tbl.insertRow(idx + 1);
var cell = row.insertCell(-1);
cell.innerHTML = '';
var cell = row.insertCell(-1);
cell.innerHTML = src.cells[1].innerHTML.replace(/(.*)(addLadder)(.*)(\[)(\+)/i, "$1removeLadder$3$4-");;
}

/**
* 删除一个价格阶梯
*/
function removeLadder(obj)
{
var row = rowindex(obj.parentNode.parentNode);
var tbl = document.getElementById('groupTable');

tbl.deleteRow(row);
}
</script>

</head>

<body>
<table id="groupTable" width="100%" cellpadding="0" cellspacing="0"
class="list_box" style="background-color: #fff;">
<tr>
<td align="right">
<b>价格阶梯:</b>
</td>
<td>
数量达到
<input type="text" name="ladder_amount[]" value="0" size="8" />
   享受价格
<input type="text" name="ladder_price[]" value="0" size="8" />
<a href="javascript:;" onclick="addLadder(this)"><strong>[+]</strong>
</a>
</td>
</tr>
</table>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值