admin管理员组文章数量:1315252
I have created a javascript which opens ckeditor on click event of div, and gets the data from the div to ckeditor, now i want something what can get that updated data from ckeditor back to that div again. and which happens dynamically.
I am using this javascript to get data from div
//var editor, html = '';
function createEditor(ele)
{
var x = ele.innerHTML;
CKEDITOR.instances.editor1.setData(x);
var y = document.getElementById("editor1").value;
alert(y);
//ele.innerHTML = y;
document.getElementById("editor1").style.display = "block";
}
</script>
And my HTML is
<div onclick="createEditor(this);" id="id2"> hello how r u? </div>
Please help me on this
I have created a javascript which opens ckeditor on click event of div, and gets the data from the div to ckeditor, now i want something what can get that updated data from ckeditor back to that div again. and which happens dynamically.
I am using this javascript to get data from div
//var editor, html = '';
function createEditor(ele)
{
var x = ele.innerHTML;
CKEDITOR.instances.editor1.setData(x);
var y = document.getElementById("editor1").value;
alert(y);
//ele.innerHTML = y;
document.getElementById("editor1").style.display = "block";
}
</script>
And my HTML is
<div onclick="createEditor(this);" id="id2"> hello how r u? </div>
Please help me on this
Share Improve this question edited Nov 21, 2012 at 9:35 Nishant Solanki asked Nov 21, 2012 at 9:13 Nishant SolankiNishant Solanki 2,1283 gold badges19 silver badges32 bronze badges2 Answers
Reset to default 4So I guess you want a live preview for CKEditor? You'll not be able to do this with the event keyup
, but you can use CKEditor events like key
(instance.on('key', doSomething());
).
Step 1: Add two elements to the page:
- textarea with ID: editor
- div with ID: preview
...
<body>
<textarea id="editor"></textarea>
<div id="preview"></div>
</body>
...
Step 2: Add javascript to detect key
events and update #preview
:
CKEDITOR.replace('editor'); //new ckeditor instance
var editor = CKEDITOR.instances.editor; //reference to instance
//on `key` event
editor.on('key', function(){
var data = editor.getData(); //reference to ckeditor data
$('#preview').html(data); //update `div` html
});
I've created a preview in JSBin.
I think, that binding onKeyUp event on your ckeditor textarea, should do the trick. http://www.w3schools./jsref/event_onkeyup.asp
本文标签: javascriptI want to get data from ckeditor dynamically to the divStack Overflow
版权声明:本文标题:javascript - I want to get data from ckeditor dynamically to the div - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741979368a2408303.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论