繁体   English   中英

Jquery 附加表

[英]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>

注意:- 您可以处理您的表idtbody

您应该尝试像这样定位您的 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM