小编Jac*_*ack的帖子

JQuery html()函数与表无法正常工作

<script type="text/javascript">
    $(document).ready(function(){
        console.log($('#list_table_template').html());
    });
</script>

<div id="list_table_template" style="display: none;">
    <table id="list_table" cellpadding="0" cellspacing="0">
        <p>123</p>
        <tr id="lt_header">
            <!--#lt_header#-->
        </tr>
        <!--#lt_listing#-->
        <tr id="lt_footer">
            <td colspan="5">Footer Placeholder</td>
        </tr>
    </table>
</div>
Run Code Online (Sandbox Code Playgroud)

此代码未返回预期结果.

虽然我期待日志显示:

    <table id="list_table" cellpadding="0" cellspacing="0">
        <p>123</p>
        <tr id="lt_header">
            <!--#lt_header#-->
        </tr>
        <!--#lt_listing#-->
        <tr id="lt_footer">
            <td colspan="5">Footer Placeholder</td>
        </tr>
    </table>
Run Code Online (Sandbox Code Playgroud)

但相反它给了我:

<p>123</p><table id="list_table" cellpadding="0" cellspacing="0">

    <tbody><tr id="lt_header">
        <!--#lt_header#-->
    </tr>
    <!--#lt_listing#-->
    <tr id="lt_footer">
        <td colspan="5">Footer Placeholder</td>
    </tr>
</tbody></table>
Run Code Online (Sandbox Code Playgroud)

请注意,p标签出现故障并跳到表格前面.

jquery html-table

0
推荐指数
1
解决办法
699
查看次数

标签 统计

html-table ×1

jquery ×1