我尝试通过javascript动态地将<tr>
与<td>
两个<table>
添加到<button type="button" onclick="myFunction()">Click Me!</button>
<table class="table table-bordered" id="chatHistoryTable">
<tr>
<td>
12:30:30
</td>
<td>
text here
</td>
</table>
中,但我的小提琴似乎没有做任何事情,是吗?有谁看到了这个问题?
小提琴:https://jsfiddle.net/otL69Lpo/2/
HTML:
function myFunction() {
var table = document.getElementById("chatHistoryTable");
var tr = document.createElement("tr");
var td = document.createElement("td");
var td2 = document.createElement("td");
var txt = document.createTextNode("TIMESTAMP");
var txt2 = document.createTextNode("user: text");
td.appendChild(txt);
td2.appendChild(txt2);
tr.appendChild(td);
tr.appendChild(td2);
table.appendChild(tr);
}
JS:
| TIMESTAMP | user: text |
输出应为:
{{1}}