使用Jquery.text()时在<p>标记内换行

kra*_*626 15 html jquery jquery-ui

我想做这样的事情:

<p> Line 1 <br/> Line 2 <br/> </p>

这不起作用,但我正在尝试做什么?

编辑:更多信息

我正在执行这行代码: $("#textDialogBox").text("test<br />test2");

这里#textDialogBox<p id = "textDialogBox">This is an animated dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>

但是当我打开对话框时,
显示为文本,而不是换行符.

Sha*_*ard 57

请改为:

$("#textDialogBox").html("test<br/>test2");
Run Code Online (Sandbox Code Playgroud)

jQuery的text()方法将"销毁"给它的任何HTML,这也包括在内<br />.