关于给一个<table>添加多条<tr>的问T,appendChild(),,,, 你应该在添加留言时动态添加Table的行和列,然后再在新加的单元格里赋值。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 document.getElementById("newNickname")每次添加的时候都是在改变同一个div的值啊 对,就是这个样子,实现动态添加<tr> <td></td>...</tr>可是怎么实现动态添加?刚开始学JS不久,,,,可能要用得appendChild()这个方法,可是实现真就不知道怎么做了,,,, tr是在 tbody下的. 不是 table下的 - - 给你一个例子:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>表格</title></head><body><button onclick="fun()">插入行</button><table border="1" id="tab"></table><script type="text/javascript">function fun(){ var tb = document.getElementById("tab").tBodies[0]; var row = tb.insertRow(0); var cell = row.insertCell(0); cell.innerHTML = "hello"; cell = row.insertCell(1); var ipt = document.createElement("input"); ipt.type = "text"; cell.appendChild(ipt);}</script></body></html> 5楼FF不通过<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>表格</title></head><body><button onclick="fun()">插入行</button><table border="1" id="tab"><tbody></tbody></table><script type="text/javascript">function fun(){ var tb = document.getElementById("tab").tBodies[0]; var row = tb.insertRow(0); var cell = row.insertCell(0); cell.innerHTML = "hello"; cell = row.insertCell(1); var ipt = document.createElement("input"); ipt.type = "text"; cell.insertBefore(ipt,null);}</script></body></html> 如何等待上传完毕后才提交表单? JAVASCRIPT:让DIV在浏览器改变大小后依然居中 jquery 怎么样根据名称获得对应的类型(TYPE)?? 已知道一个元素,怎么转成jq包装集 如何设置html文件只能使用IE打开,不能使用记事本等其他程序打开? 在Div中回车时,自动加了<p>分段标识符,行间距很大,怎么用<br>换行方式??? 请高手指点关闭窗口弹出提示信息的问题! 设为首页问题 我想调用一个js文件,应该怎么处理啊? 同样的字符串值,MD5加密不一样 平安夜散分问问题 多个输入框传递值的问题
对,就是这个样子,实现动态添加<tr> <td></td>...</tr>可是怎么实现动态添加?刚开始学JS不久,,,,可能要用得appendChild()这个方法,
可是实现真就不知道怎么做了,,,,
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>表格</title>
</head>
<body>
<button onclick="fun()">插入行</button>
<table border="1" id="tab">
</table>
<script type="text/javascript">
function fun()
{
var tb = document.getElementById("tab").tBodies[0];
var row = tb.insertRow(0);
var cell = row.insertCell(0);
cell.innerHTML = "hello";
cell = row.insertCell(1);
var ipt = document.createElement("input");
ipt.type = "text";
cell.appendChild(ipt);
}
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>表格</title>
</head>
<body>
<button onclick="fun()">插入行</button>
<table border="1" id="tab">
<tbody>
</tbody>
</table>
<script type="text/javascript">
function fun()
{
var tb = document.getElementById("tab").tBodies[0];
var row = tb.insertRow(0);
var cell = row.insertCell(0);
cell.innerHTML = "hello";
cell = row.insertCell(1);
var ipt = document.createElement("input");
ipt.type = "text";
cell.insertBefore(ipt,null);
}
</script>
</body>
</html>