用javascript实现在表格中添加新行的同时添加内容

<script type="text/javascript">
function tableAddRow(obj)
{
	var newTr = document.getElementById(obj).insertRow(); //插入新行  
	var newTd0 = newTr.insertCell();   //为行插入单元格
	var newTd1 = newTr.insertCell();   
	var newTd2 = newTr.insertCell();   
	var newTd3 = newTr.insertCell();   
	newTd0.innerHTML=document.getElementById("xm").value;//为单元格加入内容
	newTd1.innerHTML=document.getElementById("sex").value;
	newTd2.innerHTML=document.getElementById("call").value;
	newTd3.innerHTML=document.getElementById("add").value;

}
</script>
<table id="mytable" width="80%" align="center" cellpadding="5" cellspacing="5" class="" bgcolor="#00CCFF">
    	    	<tr>
        	    	<td align="center" class="td2" width="10%">姓名</td>
                    <td align="center" class="td2" width="5%">性别</td>
                    <td align="center" class="td2" width="25%">联系方式</td>
                    <td align="center" class="td2" width="40%">工作地点</td>
            	</tr>
                <tr>
                <td>赵钱孙李</td>
                <td>不男不女</td>
                <td>写信快递</td>
                <td>马勒戈壁</td>
                </tr>
            </table>             
            姓名<input type="text" name="xm"  id="xm" />
            性别<input type="text" name="sex" id="sex"/>
            联系方式<input type="text" name="call" id="call"/>
            工作地点<input type="text" name="add" id="add"/><br  />
            <input type=button value=确定添加 οnclick="tableAddRow('mytable');" />
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值