我有一个简单的问题,我有一个 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
最佳答案
在您的 jsFiddle 中,您在 JQuery 之后附加了 tinyMCE。它没有用,我已经修好了。 http://jsfiddle.net/sVs7X/3/
如您所见,评论中的问题是正确的。麻烦你芯了-\n
换行符为 <br \>
转换。你可以自己替换这个:
$("#description").val(val)
为此:
$("#description").val( val.replace( /\n/, '<br />' ) );
关于php - tinymce 中的 Jquery 文本问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16084787/