0
上的按钮,我想添加额外的表行和单元格为<table>
修改DIV的innerHTML条表标签
<input type="button" value="Add More" onclick="add_cust_fields()" />
table rows and cells here
<div id="extra_cust_field"></div>
rows and cells continue here
我JScode
function add_cust_fields() {
document.getElementById("extra_cust_field").innerHTML +=
"<tr><td>test</td><td>test2</td></tr>";
}
所有我的点击在整个桌子上面都是空的testtest2
。
你需要将这些东西附加到表格元素而不是div:'document.getElementById(“myTable”)。innerHTML + =“stuff”;' – karim79 2012-01-30 14:23:21
你不能在'table'里面有'div'。浏览器会纠正这个问题并将div移动到有效位置。在这种情况下,这似乎高于表格。 – 2012-01-30 14:24:11
可以粘贴HTML准确?在http://jsfiddle.net上? – 2012-01-30 14:24:26