Bootbox 将 DIV 标签移到 table 之外

Bootbox moving DIV tags outside of table

我正在使用 Bootbox 来显示模式。

使用 JS,我正在创建一个字符串作为消息:

display = "<b>Notes</b>";
display += "<br><br>";

display += "<table class='table' id='notes-table'>";
display += "<div>";
display += "<tr><td>";
display += "...";
display += "</td></tr>";
display += "</div>"; 
display += "</table>";

然后我调用模态:

bootbox.alert( {
    message: display,
    buttons: {
        ok: {
            label: 'Close'
        }
    }
    //Example.show("Hello world callback");
});

在控制台中记录 display,我得到:

<b>Notes</b><br><br><table class='table' id='notes-table'><div><tr><td>...</td></tr></div></table>

但是,当我检查 DOM 时,我得到:

<b>Notes</b>
<br>
<br>
<div></div>
<table class='table' id='notes-table'>
<tbody>
<tr>
<td>...</td>
</tr>
</tbody>
</table>

为什么 DIV 标签不再包裹 table?

发生这种情况是因为将 <div> 标记直接放在 <table> 标记内不是有效的 HTML 结构,因此浏览器会自动纠正该错误,并且 return 是有效的通过将 <div> 标记放在 table.

之外来表达

希望对您有所帮助。