javacript的小问题

lddx09831 2011-02-24 03:34:44
如何用jscript实现如下功能:

添加一行
aa bb cc

当点击“添加一行”按钮后表格添加一行

添加一行
aa bb cc



请复制连接到地址栏,查看实现功能
http://lddx09831.blog.163.com/blog/static/172991414201112433929358/
...全文
60 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lddx09831 2011-02-24
  • 打赏
  • 举报
回复
谢谢哈。。。
emon123 2011-02-24
  • 打赏
  • 举报
回复
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>增加Table行</title>
</head>
<script>
function addRow(obj)
{
//添加一行
var newTr = testTbl.insertRow();
//添加两列
var newTd0 = newTr.insertCell();
var newTd1 = newTr.insertCell();
//设置列内容和属性
newTd0.innerHTML = '<input type=checkbox id="box4">';
newTd1.innerText= '新加行';
}
</script>
<body>
<table id="testTbl" border=1>
<tr id="tr1">
<td ><input type=checkbox id="box1"></td>
<td id="b">第一行</td>
</tr>
<tr id="tr2">
<td ><input type=checkbox id="box2"></td>
<td id="b">第二行</td>
</tr>
<tr id="tr3">
<td ><input type=checkbox id="box3"></td>
<td>第三行</td>
</tr>
</table>
<br />
<input type="button" id="add" onclick="addRow();" value="Add Row" />
</body>
</html>
lddx09831 2011-02-24
  • 打赏
  • 举报
回复
已经很接进了,但是不是我想要的实现。。。
请复制上面的连接查看实现的功能,,谢谢啊
dashuaishuiyun 2011-02-24
  • 打赏
  • 举报
回复
参考下面:

<html>
<head>
<script type="text/javascript">
function insCell()
{
var x=document.getElementById('tr2').insertCell(2)
x.innerHTML="John"
}
</script>
</head>
<body>

<table border="1">
<tr id="tr1">
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr id="tr2">
<td>Peter</td>
<td>Griffin</td>
</tr>
</table>
<br />
<input type="button" onclick="insCell()" value="插入单元">

</body>
</html>
Joop_Song 2011-02-24
  • 打赏
  • 举报
回复
广告???

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧