[英]Jquery Append Table
html文件
<div id='tweetPost'>
<table id="example">
<thead>
<tr>
<th>No</th>
<th>FistName</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
JavaScript
$("#tweetPost").append(<tr>);
$("#tweetPost").append("<td>"+tweets.statuses[i].text + "<td/>");
$("#tweetPost").append("<td>"+tweets.statuses[i].created_at +"</td>");
$("#tweetPost").append(</tr>);
當我嘗試運行上面的代碼時,表格不會出來。
問題:如何在 tbody 中附加 td 行?
$('#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>");
table { background: #CCC; border: 1px solid #000; } table td { padding: 15px; border: 1px solid #DDD; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id='tweetPost'></div>
注意:- 您可以處理您的表id
和tbody
您應該嘗試像這樣定位您的 table id 示例和 tbody:
$("#example tbody").append("<tr><td>text</td><td>created</td></tr>");
有關工作示例,請參閱此鏈接:附加到示例表
您在div
而不是tbody
中附加了tr
並且這也是一些語法錯誤。 嘗試如下。
$("#example tbody").append("<tr><td>" + tweets.statuses[i].text + "<td/><td>" + tweets.statuses[i].created_at + "</td><tr>");
您在第一行和最后一行遺漏了引號“” 。 試試這個:
$("#tweetPost").append("<tr>");
$("#tweetPost").append("<td>"+tweets.statuses[i].text + "<td/>");
$("#tweetPost").append("<td>"+tweets.statuses[i].created_at +"</td>");
$("#tweetPost").append("</tr>");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.