3

我有一个简单的问题,我有一个文本区域,我在 jquery 中为其分配了文本。这是带有一些行空格等的纯文本。这里是一个文本示例

Brand new!!!

Huge size of 3 bedroom apartment located in Dubai Marina Orra tower for rent

Situated on high floor, overlooking a gorgeous view of Marina

现在当我分配给textarea时,它和上面一样。这是我分配的代码

$("#description").val(val);//val is above text

现在当我应用tinymce时,它变成了这样

Brand new!!! Huge size of 3 bedroom apartment located in Dubai Marina Orra tower for rent Situated on high floor, overlooking a gorgeous view of Marina

空格线打破了一切丢失。这是我的tinymce代码

$().ready(function() {
    $('#description').tinymce({
        // Location of TinyMCE script
        script_url : 'application/views/tinymce/jscripts/tiny_mce/tiny_mce.js',
        // General options
        width : "830",
        height: "300",
        theme : "advanced",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_toolbar_location : "top",
        theme_advanced_buttons1 : "bold,italic,underline,strikethrough,bullist,numlist,",
        theme_advanced_buttons2 : "",
        theme_advanced_buttons3 : "",
        theme_advanced_buttons4 : "",
        force_br_newlines : true,
        force_p_newlines : false,
        gecko_spellcheck : true,  
        forced_root_block : '', // Needed for 3.x

        plugins : "paste"


    });
});

为什么我的文字变形?小提琴

4

1 回答 1

1

在您的 jsFiddle 中,您在 JQuery 之后附加了 tinyMCE。没用,我修好了 http://jsfiddle.net/sVs7X/3/

正如您在评论中看到的问题是正确的。你的麻烦的核心 -\n换行符<br \>转换。您可以自己替换它:

$("#description").val(val)

对此:

$("#description").val( val.replace( /\n/, '<br />' ) );
于 2013-04-29T22:05:19.020 回答