我有一个简单的问题,我有一个textarea,我在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"
});
});
为什么我的文字会出现问题?fiddle
答案 0 :(得分:1)
在你的jsFiddle中你在JQuery之后添加了tinyMCE。它没有用,我已经修好了。 http://jsfiddle.net/sVs7X/3/
如您所见,评论中的问题是正确的。麻烦的核心 - \n
新行符号转换为<br \>
。您可以自己替换它:
$("#description").val(val)
到此:
$("#description").val( val.replace( /\n/, '<br />' ) );