如何在Moodle中使用jQuery获取文本区域(tinymce)的值?

时间:2015-08-21 07:13:06

标签: jquery tinymce editor moodle

如何在 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();

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

1 个答案:

答案 0 :(得分:2)

使用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是否为null,try-catch等。)

相关问题