2017-12-11 7 views
0

행을 html 테이블에 추가하려하지만 작동하지 않습니다. table.addrow를 사용하여 테이블에 행을 추가 할 수 없습니다.

나는이 코드를 실행

$('#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

이럴 InsertRow를이 JQuery와 함수가 아닙니다. 이것이이 오류를받는 이유입니다.

$(".timesTable > tbody").append("<tr><td>row content</td></tr>"); 

이 작업을 수행해야합니다.

+0

그러나, 나는 ('listTimes') 'VAR 테이블 = document.getElementById를 할 경우에도 getElementsByClassName을 ('timesTable ');'가 외설. '일하는 중 ... – Cubetastic

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>