【发布时间】:2013-02-12 16:49:09
【问题描述】:
我在 div 标签中向表添加行时遇到了一些问题,因为其中有另一个标签。
我知道如果我可以更改表的 id 会很好,但是因为它是生成的,所以我无法更改它们。我只能更改包含表格的 div 的 id。
<!--Adding does not work on this table -->
<h3>Wednesday</h3>
<button type="button" onclick="displayResult('wed')">Insert new row</button>
<div id="wed">
<strong>Even this stops it from adding</strong> <!--This is the problem -->
<table id="myTable" border="1">
<tr>
<td>cell 1</td>
<td>cell 2</td>
</tr>
</table>
<div>
<!--Adding works on this table -->
<h3>Thursday</h3>
<button type="button" onclick="displayResult('thu')">Insert new row</button>
<div id="thu">
<table id="myTable" border="1">
<tr>
<td>cell 1</td>
<td>cell 2</td>
</tr>
</table>
<div>
function displayResult(number) {
var elemList=document.getElementById(number).childNodes;
var table=elemList[1];
var row=table.insertRow(-1);
var cell1=row.insertCell(0);
var cell2=row.insertCell(1);
cell1.innerHTML="New";
cell2.innerHTML="New";
}
【问题讨论】:
-
混淆缩短器的背后是什么?请充实您的问题。
-
很高兴在这里看到一些,但链接中的小提琴很清楚有什么问题。
-
@krillgar, we like a question to contain all the content 这样,例如,如果链接坏了,问题及其答案对未来的访问者仍然有用。
-
点了,虽然这仍然不能保证否决票。不过,您的评论比 gdoron 的更好,更有建设性。
-
我做了更改.. 有人也可以解封我吗? :(
标签: javascript html asp.net-web-api