jquery - 切换tinymce编辑器后,它不发送complete字符串

标签 jquery joomla tinymce

我在 joomla 组件上使用 tinymce 编辑器,但行为奇怪

tinymce 在页面加载时已经存在(自动)..现在,如果我在微型 mce 编辑器上写一些东西(例如:' with tinymce ')然后单击 toggle editor按钮(现在出现简单的文本区域),我看到 <p>with tinymce</p>,现在,如果我附加一些文本(例如:'with tinymce but this time toggled')并单击提交按钮,那么我只得到这个字符串'with tinymce ' 在 post 数组中,不是完整的字符串 ' with tinymce but this time toggled '。

意味着如果我在页面上出现tinymce时写一些东西(让'x')然后切换编辑器现在只出现文本区域)并编辑X(让'x+Y')并单击提交然后我只得到该字符串这是在页面上出现微型 mce 时编写的(意味着我只得到“x”,而不是“x+Y”)

请告诉我我必须在下面的代码中编写什么才能获得完整的字符串,无论是使用tinymce还是不使用tinymce

我的代码如下

jQuery(document).ready(function(){    
jQuery("#add_cat").click(function() {
if(jQuery("#description_parent").is(":hidden")==false){ // if editor is shown then 
    var content = tinyMCE.activeEditor.getContent(); // get the content
    jQuery("#cat_description").val(content); // put it in the textarea
}
});

jQuery("#addCategoryForm").validate({
        rules: {
            category_name: {
                required: true,
                minlength: 2
            },          
            cat_description: "required"
        },
        messages: {
            category_name: {
                required: "Please write category name",
                minlength: "category name must consist of at least 2 characters"
            },
            cat_description:"Please write description"
        }
    });
});
</script>
<form action="" method="post" name="addCategoryForm" id="addCategoryForm"  >    
  <table >
    <tr>
        <th >Category Name :</th>
        <td ><input type="text" name="category_name" id="category_name" size="50"></td>
    </tr>       
    <tr>
       <th valign="top"><span class="mandatory">*</span>Description :</th>
       <td >
    <?php
        $editor =& JFactory::getEditor();
        $params = array('smilies'=> '0' ,'style'  => '0' ,'layer'  => '0' ,'table'  => '0' ,'clear_entities'=>'0');
        $value = isset($this->data['description']) ? $this->data['description'] : '';
        echo $editor->display('cat_description', $value,'400','300','20','20',false, $params);
    ?>
      </td>
    </tr>   
    <tr><td colspan="2"><input type="submit" name="add_cat" id="add_cat" ></td>
  </table>
  <input type='hidden' value='com_advertise' name='option' />
  <input type='hidden' value='advertise' name='controller' />   
  <input type='hidden' value='modifyCategory' name='task' />
  <input type="hidden" value='<?php echo $this->imageid; ?>' name="image_id" /> 
  <input type='hidden' value='<?php echo $this->categoryid; ?>' name='category_id' />   
  <input type="hidden" name="<?php echo JUtility::getToken(); ?>" value="1" />
</form>

最佳答案

嗯。 Tinymce 使用隐藏的文本区域来存储编辑器内容。我只是猜测您的 joomla 提交没有更新该文本区域。在这种情况下,您需要在提交之前调用tinymces save 函数。其代码(作为tinymce插件中的事件处理程序)可能如下所示(您可能需要使用除onChange之外的另一个合适的编辑器事件):

//call save using an event handler
ed.onChange.add(function(editor, event){
       editor.save();
});

// call save directly without handler
editor_instance = tinymce.EditorManager.getInstanceById('content'); // 'content' is used as default editor id, it might be another id

editor_instance.save();

关于jquery - 切换tinymce编辑器后,它不发送complete字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3201505/

相关文章:

javascript - 无法在 jquery .load() 外部内容后滚动

joomla - 如何在 Joomla Controller 中显示 View ?

javascript - 在 Joomla 中加载脚本标签的问题

javascript - Tiny_mce - 无法设置宽度

javascript - jQuery 数据(...)没有存储在 DOM 中?

jquery - 如何在 jquery 中定位最后一个 tr?

javascript - TinyMCE,显示字符数而不是字数

jquery - Tinymce 和带分页符的打印

javascript onscroll淡入淡出相同的类但具有不同的div

joomla - 从类别 ID 显示文章的代码?