2015-07-12 51 views
-3

我需要從CK編輯器獲取內容以將其放入JQuery中。如何從CK編輯器獲取內容?

\t 
 
\t \t \t \t <form action="php/showcomments.php" method="post" onsubmit="return false;" > 
 
\t \t \t \t <div class="text-cmt"> 
 
\t \t \t \t \t <input id="tittle" name="tittle" type="text" placeholder="Comment Title" id="comm" required/> 
 
\t \t \t \t </div> 
 
\t \t \t \t <div class="text-cmt"> 
 
\t \t \t \t \t <textarea id="msg" ></textarea> 
 
\t 
 
\t \t \t \t </div> 
 
\t \t \t \t <div class="text-cmt"> 
 
\t \t \t \t \t <input name="send" type="submit" value="send"> 
 
\t \t \t \t </div> 
 
\t \t \t \t </form> 
 
\t \t \t \t \t <script> 
 
     CKEDITOR.replace('msg'); 
 
    </script>

<script> 
 
$(document).ready(function(){ 
 
\t var g_id = "<?= $id; ?>"; 
 
\t var u_id = "<?= userid; ?>"; 
 
\t 
 
    // var comm = tinyMCE.editor.getContent(); 
 
\t //tinyMCE.get('editor').getContent() 
 
\t $("form").submit(function(){ 
 
\t \t var comm = $("#tittle").val(); 
 
    \t $.ajax({ 
 
     url: 'php/showcomments.php', // form action url 
 
     type: 'POST', // form submit method get/post 
 
     data: {tittle: $("#tittle").val(),comm: comm, g_id: g_id, u_id: u_id }, 
 
     dataType: 'html', 
 
\t success: function(data) 
 
\t { 
 
\t \t alert(data); 
 
     }, 
 
\t }); 
 
    }); 
 
}); 
 
</script>

+0

請提供錯誤信息,也活頁網址,我們可以檢查錯誤和CKEditor的佈局 –

回答

3

可以使用

JS的CKEditor的獲得3.6.x的CK編輯的內容

var editor = CKEDITOR.editor.replace('msg'); 

$('#send').click(function() { 
    var value = editor.getData(); 
    // send your ajax request with value 
    // profit! 
}); 

JS的CKEditor的4.0.x的

$('#send').click(function() { 
    var value = CKEDITOR.instances['DOM-ID-HERE'].getData() 
    // send your ajax request with value 
    // profit! 
}); 
+0

不是從文字區域,但是從CKEditor的 –

+0

更新代碼來獲取爲ckeditor –

+0

謝謝:) 你幫我:) –