我试图将行添加到html表,但它不起作用。
$('#listTimes .timesList').html('\
<table class="timesTable">\
<tr>\
<th>No.</th>\
<th>Time</th>\
<th>Avg. of 5</th>\
</tr>\
</table>');
var table = $('#listTimes table');
//Some code
var row = table.insertRow();//This is where the error occurs
当我运行此代码时,我收到以下错误:
Uncaught TypeError: table.insertRow is not a function at saveTimes.js:44 at DataSnapshot.js:126 at e.inorderTraversal (SortedMap.js:170) at e.inorderTraversal (SortedMap.js:169) at e.inorderTraversal (SortedMap.js:169) at e.inorderTraversal (SortedMap.js:169) at e.inorderTraversal (SortedMap.js:169) at e.inorderTraversal (SortedMap.js:169) at e.inorderTraversal (SortedMap.js:169) at e.inorderTraversal (SortedMap.js:169) (anonymous) @ saveTimes.js:44 (anonymous) @ DataSnapshot.js:126 e.inorderTraversal @ SortedMap.js:170 e.inorderTraversal @ SortedMap.js:169 e.inorderTraversal @ SortedMap.js:169 e.inorderTraversal @ SortedMap.js:169 e.inorderTraversal @ SortedMap.js:169 e.inorderTraversal @ SortedMap.js:169 e.inorderTraversal @ SortedMap.js:169 e.inorderTraversal @ SortedMap.js:169 e.inorderTraversal @ SortedMap.js:169 e.inorderTraversal @ SortedMap.js:169 e.inorderTraversal @ SortedMap.js:618 e.forEachChild @ ChildrenNode.js:287 e.forEach @ DataSnapshot.js:125 (anonymous) @ saveTimes.js:34 (anonymous) @ EventRegistration.js:65 t.exceptionGuard @ util.js:556 e.raise @ EventQueue.js:158 e.si @ EventQueue.js:111 e.raiseEventsForChangedPath @ EventQueue.js:95 e.ee @ Repo.js:200 t.It @ PersistentConnection.js:458 t.wt @ PersistentConnection.js:452 e.wt @ Connection.js:262 e.sn @ Connection.js:256 (anonymous) @ Connection.js:157 t.xn @ WebSocketConnection.js:197 t.handleIncomingFrame @ WebSocketConnection.js:247 mySock.onmessage @ WebSocketConnection.js:144 setTimeout (async) t.exceptionGuard @ util.js:560 e.raise @ EventQueue.js:158 e.si @ EventQueue.js:111 e.raiseEventsForChangedPath @ EventQueue.js:95 e.ee @ Repo.js:200 t.It @ PersistentConnection.js:458 t.wt @ PersistentConnection.js:452 e.wt @ Connection.js:262 e.sn @ Connection.js:256 (anonymous) @ Connection.js:157 t.xn @ WebSocketConnection.js:197 t.handleIncomingFrame @ WebSocketConnection.js:247 mySock.onmessage @ WebSocketConnection.js:144
答案 0 :(得分:0)
imho insertRow不是jquery函数。这就是你收到这个错误的原因。
$(".timesTable > tbody").append("<tr><td>row content</td></tr>");
这应该可以胜任。
答案 1 :(得分:0)
你可以试试这个:
$('#listTimes .timesList').html('\
<table class="timesTable">\
<tr>\
<th>No.</th>\
<th>Time</th>\
<th>Avg. of 5</th>\
</tr>\
</table>');
var table = $('#listTimes table');
//Some code
$(".timesList").html(table);
$(".timesTable > tbody").append("<tr><td>content1</td><td>content2</td><td>content3</td></tr>");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="listTimes">
<div class="timesList">
</div>