peg*_*sus 53 ajax jquery ckeditor
我正在使用CKEditor.我使用页面方法使用ajax保存表单值.
但是CKEditor值的内容无法保存到表中.
我不回发页面.
我该怎么办?
Aeo*_*eon 191
在实例上使用CKEditor.editor.getData()调用.也就是说:
HTML
<textarea id="my-editor">
<input id="send" type="button" value="Send">
Run Code Online (Sandbox Code Playgroud)
JS for CKEditor 4.0.x
$('#send').click(function() {
var value = CKEDITOR.instances['DOM-ID-HERE'].getData()
// send your ajax request with value
// profit!
});
Run Code Online (Sandbox Code Playgroud)
JS for CKEditor 3.6.x.
var editor = CKEDITOR.editor.replace('my-editor');
$('#send').click(function() {
var value = editor.getData();
// send your ajax request with value
// profit!
});
Run Code Online (Sandbox Code Playgroud)
jve*_*rdi 63
如果您没有对编辑器的引用,如Aeon的答案,您也可以使用以下表单:
var value = CKEDITOR.instances['my-editor'].getData();
Run Code Online (Sandbox Code Playgroud)
小智 9
var value = CKEDITOR.instances['YourInstanceName'].getData()
alert( value);
Run Code Online (Sandbox Code Playgroud)
替换YourInstanceName
为您的实例名称,您将获得所需的结果.
我getData()
每次都没有工作的问题,特别是在处理现场ajax时.
能够通过运行绕过它:
for(var instanceName in CKEDITOR.instances){
CKEDITOR.instances[instanceName].updateElement();
}
Run Code Online (Sandbox Code Playgroud)
然后使用jquery从textarea中获取值.
现在jQuery 适配器已经存在,这个答案需要更新:
假设您启动了编辑器,$('.ckeditor').ckeditor(opt)
然后您获得了值$('.ckeditor').val()
Mik*_*ike -21
首先,您应该在页面中包含 ckeditor 和 jquery 连接器脚本,
然后创建一个文本区域
<textarea name="content" class="editor" id="ms_editor"></textarea>
Run Code Online (Sandbox Code Playgroud)
将ckeditor附加到文本区域,在我的项目中我使用这样的东西:
$('textarea.editor').ckeditor(function() {
}, { toolbar : [
['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
['Undo','Redo'],
['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
['Link','Unlink','Anchor', 'Image', 'Smiley'],
['Table','HorizontalRule','SpecialChar'],
['Styles','BGColor']
], toolbarCanCollapse:false, height: '300px', scayt_sLang: 'pt_PT', uiColor : '#EBEBEB' } );
Run Code Online (Sandbox Code Playgroud)
提交时使用以下方式获取内容:
var content = $( 'textarea.editor' ).val();
Run Code Online (Sandbox Code Playgroud)
就是这样!:)
归档时间: |
|
查看次数: |
121440 次 |
最近记录: |