html 动态添加TABLE的行。

时间:2014-03-11 07:03:21   收藏:0   阅读:515
bubuko.com,布布扣
<script type="text/javascript"> 
var pos =4;//默认位置为4,根据自己需要,也可以通过鼠标事件获取当前行数。

function insRow() //增加TR
{ 
var x=document.getElementById(‘fb‘).insertRow(pos) ;
x.innerHTML= "<tr>                    <td width=\"9%\" height=\"50\" align=\"center\">版本:</td>                    <td width=\"23%\" align=\"left\"><input                        id=\"input_product_class\" class=\"input-block-level\"name=\"version\" type=\"text\"></td>                    <td width=\"6%\" align=\"center\">价格:</td>                    <td width=\"26%\" align=\"left\"><input id=\"input_product_price\" class=\"input-block-level\" name=\"pricePerUnit\" type=\"text\"></td>                    <td width=\"10%\" align=\"center\">促销价格:</td>                    <td width=\"26%\" align=\"left\"><input id=\"input_product_inventory\" class=\"input-block-level\" name=\"inventory\" type=\"text\"></td>                    <tdn onclick=\"delRow()\" class=\"close\">×<td>                    </tr>";


pos=pos+1;
}
function delRow()//删除TR,不过只能从后向前依次删除,否则就或删错。因为我的POS不是鼠标获取的,所以无法随意删除。
{ 
    document.getElementById(‘fb‘).deleteRow(pos-1);
    pos=pos-1;
}


</script>
bubuko.com,布布扣

html 动态添加TABLE的行。,布布扣,bubuko.com

原文:http://www.cnblogs.com/shenghaishiweini/p/3591315.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!