html标签插入换行符 [英] html label inserting newline
本文介绍了html标签插入换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用jQuery动态地将一些文本设置为标签。但是我无法获得< br>
或 \ n
来渲染并给我换行。它显示在同一行并包装。
I'm trying to set some text to a label dynamically using jQuery. But i can't get the <br>
or \n
to render and give me new lines. It all shows up on the same line and wraps.
这是我的代码 On JsFiddle
我的html:
<label id="myLabel" />
我的Javascript:
My Javascript:
$("#myLabel").text("This is my first line \n This should be my second line.");
推荐答案
text()
将转义任何html代码,因此请使用 html()
text()
will escape any html code, so instead use html()
$("#myLabel").html("This is my first line <br /> This should be my second line.");
这篇关于html标签插入换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文