JavaScript document.write br

时间:2016-03-01 17:36:12

标签: javascript document.write

你如何用JavaScript "<br>"写作?我不希望它打破并转到下一行,我只想写html标签。类似于:“html中的break标记是......”

以下我想要的例子。

<script type = "text/javascript">
    document.write('"<br>"');
</script>

2 个答案:

答案 0 :(得分:1)

只需使用HTML entities

Character  Entity   Note
---------  -------  ----------------------------------------------------------------
    &      &amp;    Character indicates the beginning of an entity. 
    <      &lt;     Character indicates the beginning of a tag 
    >      &gt;     Character indicates the ending of a tag 
    "      &quote;  Character indicates the beginning and end of an attribute value. 

document.write('The break tag in html is &lt;br&gt;.');

答案 1 :(得分:0)

您可以使用<>的HTML实体:

< : &lt;
> : &gt;

&lt;br&gt; = <br>

这会有所帮助。

&#13;
&#13;
document.write("I don't want &lt;br&gt; to break and go to the next line");
&#13;
&#13;
&#13;