JQuery를 사용하여 CKEditor의 콘텐츠를 어떻게 얻을 수 있습니까?
CKEditor를 사용하고 있습니다. 페이지 메서드를 사용하여 ajax로 양식 값을 저장하고 있습니다.
그러나 CKEditor 값의 내용은 테이블에 저장할 수 없습니다.
페이지를 포스트 백하지 않습니다.
그것을 위해 무엇을 할 수 있습니까?
먼저 페이지에 ckeditor 및 jquery 커넥터 스크립트를 포함해야합니다.
그런 다음 텍스트 영역을 만듭니다.
<textarea name="content" class="editor" id="ms_editor"></textarea>
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' } );
제출시 다음을 사용하여 콘텐츠를 가져옵니다.
var content = $( 'textarea.editor' ).val();
그게 다야! :)
인스턴스 에서 CKEditor.editor.getData () 호출을 사용하십시오. 즉 말하자면:
HTML
<textarea id="my-editor">
<input id="send" type="button" value="Send">
CKEditor 4.0.x 용 JS
$('#send').click(function() {
var value = CKEDITOR.instances['DOM-ID-HERE'].getData()
// send your ajax request with value
// profit!
});
CKEditor 3.6.x 용 JS
var editor = CKEDITOR.editor.replace('my-editor');
$('#send').click(function() {
var value = editor.getData();
// send your ajax request with value
// profit!
});
Aeon의 답변과 같이 편집기에 대한 참조가 없으면 다음 양식을 사용할 수도 있습니다.
var value = CKEDITOR.instances['my-editor'].getData();
var value = CKEDITOR.instances['YourInstanceName'].getData()
alert( value);
교체 YourInstanceName
인스턴스의 이름으로 당신이 원하는 결과를 얻을 수 있습니다.
getData()
특히 라이브 아약스를 다룰 때 매번 작동하지 않는 문제가 발생했습니다 .
다음을 실행하여 문제를 해결할 수있었습니다.
for(var instanceName in CKEDITOR.instances){
CKEDITOR.instances[instanceName].updateElement();
}
그런 다음 jquery를 사용하여 텍스트 영역에서 값을 가져옵니다.
John Magnolia에게 감사드립니다. 이것은 Symfony 프로젝트에서 사용하는 postForm 함수이며 이제 CK 편집기로 작업하는 것이 좋습니다.
function postForm($form, callback)
{
// Get all form values
var values = {};
var fields = {};
for(var instanceName in CKEDITOR.instances){
CKEDITOR.instances[instanceName].updateElement();
}
$.each($form.serializeArray(), function(i, field) {
values[field.name] = field.value;
});
// Throw the form values to the server!
$.ajax({
type : $form.attr('method'),
url : $form.attr('action'),
data : values,
success : function(data) {
callback( data );
}
});
이제 jQuery 어댑터 가 존재 하므로이 답변을 업데이트해야합니다.
편집기를 시작했다고 가정하면 $('.ckeditor').ckeditor(opt)
다음으로 가치를 얻습니다.$('.ckeditor').val()
다음과 같은 데이터를 검색 할 수 있습니다.
<script>
var data = CKEDITOR.instances.editor1.getData();
// Your code to save "data", usually through Ajax.
</script>
참조 : http://docs.ckeditor.com/#!/guide/dev_savedata
도구 상자에 DLL을 추가하여 ckEditor를 추가합니다.
html 코드 :
<CKEditor:CKEditorControl ID="editor1" runat="server"
BasePath="ckeditor" ContentsCss="ckeditor/contents.css"
Height="250px"
TemplatesFiles="ckeditor/themes/default/theme.js" FilebrowserBrowseUrl="ckeditor/plugins/FileManager/index.html"
FilebrowserFlashBrowseUrl="ckeditor/plugins/FileManager/index.html" FilebrowserFlashUploadUrl="ckeditor/plugins/FileManager/index.html"
FilebrowserImageBrowseLinkUrl="ckeditor/plugins/FileManager/index.html" FilebrowserImageBrowseUrl="ckeditor/plugins/FileManager/index.html"
FilebrowserImageUploadUrl="ckeditor/plugins/FileManager/index.html"
FilebrowserUploadUrl="ckeditor/plugins/FileManager/index.html" BackColor="#FF0066"
DialogButtonsOrder="Rtl"
FontNames="B Yekan;B Yekan,tahoma;Arial/Arial, Helvetica, sans-serif; Comic Sans MS/Comic Sans MS, cursive; Courier New/Courier New, Courier, monospace; Georgia/Georgia, serif; Lucida Sans Unicode/Lucida Sans Unicode, Lucida Grande, sans-serif; Tahoma/Tahoma, Geneva, sans-serif; Times New Roman/Times New Roman, Times, serif; Trebuchet MS/Trebuchet MS, Helvetica, sans-serif; Verdana/Verdana, Geneva, sans-serif"
ResizeDir="Vertical" ResizeMinHeight="350" UIColor="#CACACA">dhd fdh</CKEditor:CKEditorControl>
그것의 데이터를 얻기 위해.
jquery :
var editor = $('textarea iframe html body').html();
alert(editor);
나는 그것이 더 나을 것이라고 생각한다. jquery와 응원으로 양식을 직렬화하십시오 ...
<form id="ajxForm">
<!-- input elments here -->
<textarea id="ck-editor" name="ck-editor" required></textarea>
<input name="text" id="text" type="text" required>
<form>
및 자바 스크립트 섹션에서
CKEDITOR.replace('ck-editor', {
extraPlugins: 'sourcedialog',
removePlugins: 'sourcearea'
});
$("form#ajxForm").submit(function(e) {
e.preventDefault();
var data = $(this).serialize();
if (data != '') {
$.ajax({
url: 'post.php',
cache: false,
type: 'POST',
data: data,
success: function(e) {
setTimeout(function() {
alert(e);
}, 6500);
}
});
}
return;
});
version 4.6
CKEDITOR.instances.editor.getData()
Easy way to get the text inside of the editor or the length of it :)
var editorText = CKEDITOR.instances['<%= your_editor.ClientID %>'].getData();
alert(editorText);
var editorTextLength = CKEDITOR.instances['<%= your_editor.ClientID %>'].getData().length;
alert(editorTextLength);
version 4.8.0
$('textarea').data('ckeditorInstance').getData();
To get data of ckeditor, you need to get ckeditor instance
HTML code:
<textarea class="form-control" id="reply_mail_msg" name="message" rows="3" data-form-field="Message" placeholder="" autofocus="" style="display: none;"></textarea>
Javascript:
var ck_ed = CKEDITOR.instances.reply_mail_msg.getData();
ReferenceURL : https://stackoverflow.com/questions/3799317/how-can-i-get-content-of-ckeditor-using-jquery
'programing' 카테고리의 다른 글
.NET에서 이중 곱셈이 끊어 집니까? (0) | 2021.01.16 |
---|---|
Python의 항목 빈도 수 (0) | 2021.01.16 |
Hunk # 1 FAILED at 1 그게 무슨 뜻입니까? (0) | 2021.01.15 |
NodeJS :“EventEmitter 메모리 누수가 감지되었습니다. (0) | 2021.01.15 |
음, PRIu64는 누구입니까? (0) | 2021.01.15 |