php - tinymce 中的 Jquery 文本问题

标签 php jquery tinymce

我有一个简单的问题,我有一个 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/

相关文章:

javascript - 两个 div(一个带有 tinymce)共享一个滚动条

PHP MySQL 查询将动态字段值与其他字段动态匹配值条件相匹配

php - 操作数应包含 1 列 UPDATE

javascript - 嵌套 'for' 循环创建表

javascript - 跨多个应用程序共享 TinyMCE 插件

php - 从 WP Editor TinyMCE 中删除特定按钮

php - SELECT userinformation 其中 userid 位于最多行

PHP, Javascript, ActiveX, 头痛

javascript - jQuery 动画函数的愚蠢问题

javascript - 通过 AJAX POST 将 JSON 或 JS 对象与表单数据一起传递到 PHP 的最有效方法