Javascript Jquery.text()不能换行

Javascript Jquery.text()不能换行,javascript,jquery,Javascript,Jquery,我的代码绝对正常,但唯一的问题是.text()无法打断来自数据库的行,所有结果都在一行中,并且在我的文本开始之前对话框中已经有一些空白。我不想使用.html(),因为它的所有特殊字符都与我的数据库中的字符相同 $(document).ready(function() { var record; //set up the button styling and click functionality $('.editButton').button({ ico

我的代码绝对正常,但唯一的问题是
.text()
无法打断来自数据库的行,所有结果都在一行中,并且在我的文本开始之前对话框中已经有一些空白。我不想使用
.html()
,因为它的所有特殊字符都与我的数据库中的字符相同

$(document).ready(function() {
    var record;

    //set up the button styling and click functionality
    $('.editButton').button({
        icons: {
            primary: "ui-icon-document"
        }
    }).click(function() {
        //set which record we're editing so we can update it later
        record = $(this).parents('.record');
        //populate the editing form within the dialog

        $('#Title').val(record.find('.sh_title').text());
        $('#Post').val(record.find('.sh_post').text());
        $('#PostId').val(record.find('.postid').text());

        //show the dialog
        $("#dialogContent").dialog("open");
    });    

    //set up the dialog box.
    $("#dialogContent").dialog({
        autoOpen: false,
        modal: true,
        buttons: {
            OK: function() {
                record.find('.sh_title').text($('#Title').val());
                record.find('.sh_post').text($('#Post').val());
                $(this).dialog("close");
            },
            Cancel: function() {
                $(this).dialog("close");
            }
        }
    });
});
$(文档).ready(函数(){
var记录;
//设置按钮样式并单击功能
$('.editButton')。单击(函数(){
//设置要编辑的记录,以便稍后更新
record=$(this.parents('.record');
//在对话框中填充编辑表单
$('#Title').val(cleanText(record.find('.sh#Title').html());
$('#Post').val(cleanText(record.find('.sh#Post').html());
$('#PostId').val(cleanText(record.find('.PostId').html());
//显示对话框
//$(“#dialogContent”)。对话框(“打开”);
返回false;
});
//设置对话框。
$(“#dialogContent”).dialog({
自动打开:错误,
莫代尔:是的,
按钮:{
OK:函数(){
record.find('.sh#title').text($('#title').val());
record.find('.sh#u post').text($('#post').val());
$(此).dialog(“关闭”);
},
取消:函数(){
$(此).dialog(“关闭”);
}
}
});
});
函数cleanText(text){调试器;
text=text.replace(//mg,“

”); text=text.replace(//mg,“
”); text=text.replace(//mg,“\n”); text=text.replace(/)/ig; 返回文本。替换(regex,“”); } 函数htmlDecode(输入){ var e=document.createElement('div'); e、 innerHTML=输入; 返回e.innerText; }

标题
这是新的内容
1.
标题2
这是内容2
新内容
第2行 2. >职称 >描述 >身份证
使用html()而不是.text()。我想像1那样断行
2
3结果是1 2 3,但在对话框中显示123,如果有回车符,请使用.html($('.'Post').val()。替换(/(?:\r\n | \r | \n)/g,
)@ShailendraSharma使用html()有一个问题,问题是假设在我的数据库中保存了特殊字符,所有字符都显示在对话框中,我想显示html解码字符hey@aprovent,我可以在哪一行使用好的,那么html是什么?您的任何帮助,对meCan来说都是宝贵的我有html内容?我可以在哪里向您发送html,在评论中,有足够多的词来形容我们。