如何在 Moodle 中使用 jQuery 获取文本区域(tinymce)的值?
How to get the value of text area(tinymce) using jQuery in 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));
我的 jQuery 获取 value of editor
字段的代码是:
var answer = $("#ans").val();
但是这段代码不起作用,什么也没给出。
使用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 等)
如何在 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));
我的 jQuery 获取 value of editor
字段的代码是:
var answer = $("#ans").val();
但是这段代码不起作用,什么也没给出。
使用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 等)