2016-04-10 25 views
0

html dosyasıjQuery ekleme Tablo

<div id='tweetPost'> 
    <table id="example"> 
     <thead> 
      <tr> 
       <th>No</th> 
       <th>FistName</th> 
      </tr> 
     </thead> 

     <tbody></tbody> 

    </table> 
</div> 

Javscript kodu Üstü

$("#tweetPost").append(<tr>); 

$("#tweetPost").append("<td>"+tweets.statuses[i].text + "<td/>"); 
$("#tweetPost").append("<td>"+tweets.statuses[i].created_at +"</td>"); 

$("#tweetPost").append(</tr>); 

i çalıştırmayı deneyin tablo dışarı çıkmıyor.

Soru: td satırını tbody içine nasıl ekleyebilirim?

+0

herhangi kullanıyor musunuz:

$("#example tbody").append("<tr><td>text</td><td>created</td></tr>"); 

bir çalışma örneği için bu bağlantıya bakın döngü için? – Harish

cevap

0

Sen div yerine tbody içinde tr ekleme ve ayrıca bazı yazım hatasıdır. Takip etmeyi dene.

$("#example tbody").append("<tr><td>" + tweets.statuses[i].text + "<td/><td>" + tweets.statuses[i].created_at + "</td><tr>"); 
0

Sen ilk ve son satırları virgül "" ters kaçırdılar ettik. Bu deneyin:

$("#tweetPost").append("<tr>"); 

$("#tweetPost").append("<td>"+tweets.statuses[i].text + "<td/>"); 
$("#tweetPost").append("<td>"+tweets.statuses[i].created_at +"</td>"); 

$("#tweetPost").append("</tr>"); 
1
<!DOCTYPE html> 
<html> 
<head> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
    <style media="screen"> 
    table{background:#CCC;border:1px solid #000;} 
    table td{padding:15px;border:1px solid #DDD;} 
    </style> 
</head> 
<body> 
    <div id='tweetPost'></div> 
    <script type="text/javascript"> 
    $('#tweetPost').append('<table></table>'); 
    var table = $('#tweetPost').children(); 
    table.append("<tr><td>a</td><td>b</td></tr>"); 
    table.append("<tr><td>c</td><td>d</td></tr>"); 
    </script> 
</body> 
</html>