Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript html标签插入换行符_Javascript_Jquery_Html - Fatal编程技术网

Javascript html标签插入换行符

Javascript html标签插入换行符,javascript,jquery,html,Javascript,Jquery,Html,我正在尝试使用jQuery动态地将一些文本设置为标签。但是我不能让或\n渲染并给我新行。所有这些都显示在同一行上,并进行包装 这是我的密码 我的html: <label id="myLabel" /> text()将转义任何html代码,因此使用html() $(“#myLabel”).html(“这是我的第一行这应该是我的第二行。”); 试试这个: $('#myLabel') .html('this is my first line<br/>This shou

我正在尝试使用jQuery动态地将一些文本设置为标签。但是我不能让

\n
渲染并给我新行。所有这些都显示在同一行上,并进行包装

这是我的密码

我的html:

<label id="myLabel" />
text()
将转义任何html代码,因此使用
html()

$(“#myLabel”).html(“这是我的第一行
这应该是我的第二行。”);
试试这个:

$('#myLabel')
    .html('this is my first line<br/>This should be my second line.');
$(“#myLabel”)
.html('这是我的第一行。
这应该是我的第二行。');
问题是
.text()
将忽略您的html。你应该使用
.html()
,你可以在一个元素中放入任何你想要的html。所以你会:

$('#myLabel').html('This is my first line <br/> This should be my second line.');
$('#myLabel').html('这是我的第一行
这应该是我的第二行');
希望这有帮助。干杯

$('#myLabel')
    .html('this is my first line<br/>This should be my second line.');
$('#myLabel').html('This is my first line <br/> This should be my second line.');