【问题标题】:How to get the value of text area(tinymce) using jQuery in Moodle?如何在 Moodle 中使用 jQuery 获取文本区域(tinymce)的值?
【发布时间】:2015-08-21 07:13:05
【问题描述】:

如何在 Moodle 中使用 jQuery 获取text area(tinymce) 的值 我的文字区号是:

$editor = \editors_get_preferred_editor();
$editor->use_editor("ans");
echo \html_writer::tag('textarea', '',
    array('id' => "ans", 'name' => "ans", 'rows' => 5, 'cols' => 5));

我获取value of editor字段的jQuery代码是:

 var answer = $("#ans").val();

但是这段代码不起作用,什么也没有。

【问题讨论】:

    标签: jquery tinymce editor moodle


    【解决方案1】:

    使用 tinymce api:

    // Get the HTML contents of the currently active editor
    console.debug(tinyMCE.activeEditor.getContent());
    
    
    // Get the raw contents of the currently active editor
    tinyMCE.activeEditor.getContent({format : 'raw'});
    
    
    // Get content of a specific editor:
    tinyMCE.get('content id').getContent();
    

    在此代码之前检查用户使用哪个编辑器(检查 tinyMCE 是否为空、try-catch 等)

    【讨论】:

      猜你喜欢
      • 2011-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-07
      • 2013-04-07
      • 2022-12-04
      • 2019-07-18
      相关资源
      最近更新 更多