<table id="test">
<tbody>
</tbody>
</table>
<script>
str="<tr><td>3<weeks<=9</td></tr>";
$('#test tbody').html('str');
</script>
输出即将:在表3 作为一列,因为“<”将当作HTML标记。如何解决这个问题。我想填充3<周< = 9表如何填充2 <周<9从JavaScript以HTML表格
<table id="test">
<tbody>
</tbody>
</table>
<script>
str="<tr><td>3<weeks<=9</td></tr>";
$('#test tbody').html('str');
</script>
输出即将:在表3 作为一列,因为“<”将当作HTML标记。如何解决这个问题。我想填充3<周< = 9表如何填充2 <周<9从JavaScript以HTML表格
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="test">
<tbody>
</tbody>
</table>
<script>
str = "<tr><td>3<weeks<=9</td></tr>";
// --^-- --^--
$('#test tbody').html(str);
</script>
参见:http://www.w3.org/TR/html4/sgml/entities.html
或者您可以使用jQuery通过使用jQuery生成元素来完成该任务。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="test">
<tbody>
</tbody>
</table>
<script>
$('<tr>', {
html: $('<td>', {
text: '3<weeks<=9'
})
}).appendTo('#test tbody');
</script>
所有你需要在这种情况下做的就是逃避“<”性格,使其不作为HTML处理。转义字符HTML代码'<'在这种情况下是'& lt;'。希望这可以帮助你
谢谢4castle只是自己编辑评论 – BanelingRush
添加到答案还有很多其他这样的HTML实体**,如[列在这里](http://character-code.com/)。 –