合并使用 Ajax 调用的 HTML 表

我怎样才能合并这个表?自动将标签添加"</tr> </table>"到我使用 Ajax 调用的表格末尾 是否可以防止这种情况?


索引.php


<table border="1" width="40%" id="dynamic_content">

    <td>&nbsp;</td>

    <td>&nbsp;</td>

    </tr>

</table>


<script type="application/javascript">

    $.ajax({

        url:"ajax.php",

        method:"POST",

        success:function(data)

        {

            $('#dynamic_content').html(data);

        }

    });

</script>

ajax.php


<tr>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

</tr>

<tr>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

</tr>

<tr>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

    <td>&nbsp;</td>

</tr>


慕少森
浏览 101回答 1
1回答

隔江千里

像这样更改代码&nbsp; &nbsp; <div id="dynamic_content_div">&nbsp; &nbsp; &nbsp; &nbsp; <table border="1" width="40%" id="dynamic_content">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>&nbsp;</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>&nbsp;</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </tr>&nbsp; &nbsp; &nbsp; &nbsp; </table>&nbsp; &nbsp; </div>&nbsp; &nbsp; $.ajax({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; url:"ajax.php",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; method:"POST",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; success:function(data)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('#dynamic_content_div').html("<table border=\"1\" width=\"40%\" >"+data+" <td>&nbsp;</td><td>&nbsp;</td></tr></table>");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; });
打开App,查看更多内容
随时随地看视频慕课网APP