如何从CK编辑器获取内容?

时间:2015-07-12 18:07:19

标签: jquery ckeditor textarea

我需要从CK编辑器获取内容以将其放入JQuery中。

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

<script>
$(document).ready(function(){
	var g_id = "<?= $id; ?>";
	var u_id = "<?= userid; ?>";
	
  //  var comm = tinyMCE.editor.getContent();
	//tinyMCE.get('editor').getContent()
	  $("form").submit(function(){
		  var comm =  $("#tittle").val();
   	 $.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',
	  success: function(data)
	  {
		  alert(data);
      },
	 });
    });
});
</script>

2 个答案:

答案 0 :(得分:4)

您可以使用

获取ck编辑器的内容

JS for CKEditor 3.6.x

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

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

JS for CKEditor 4.0.x

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

答案 1 :(得分:0)

使用(您从数据库获取的值)|安全。