最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to delete the selected text from CKEditor? - Stack Overflow

programmeradmin1浏览0评论

I am developing an application where I am using CKEditor. I have provided a button called clear. Whenever user selects some part of text and clicks on clear button only the selected text should get deleted.

I used the below code in my application but whenever user clicks on clear button not only selected text but whole content gets deleted.

 function clear_onclick() {
        CKEDITOR.instances.message.setData('');
 }

How can I clear the selected text from CKEditor on click of clear button in ASP.Net MVC2?

I am developing an application where I am using CKEditor. I have provided a button called clear. Whenever user selects some part of text and clicks on clear button only the selected text should get deleted.

I used the below code in my application but whenever user clicks on clear button not only selected text but whole content gets deleted.

 function clear_onclick() {
        CKEDITOR.instances.message.setData('');
 }

How can I clear the selected text from CKEditor on click of clear button in ASP.Net MVC2?

Share edited Mar 25, 2013 at 9:15 rouen 5,1342 gold badges26 silver badges51 bronze badges asked Mar 25, 2013 at 6:49 user2031327user2031327
Add a ment  | 

2 Answers 2

Reset to default 11

This will do the job:

var range = CKEDITOR.instances.editor1.getSelection().getRanges()[ 0 ];
range.deleteContents();
range.select(); // Select emptied range to place the caret in its place.

Try this:

CKEDITOR.instances["textAreaId"].getSelection().getSelectedText().setData('');
发布评论

评论列表(0)

  1. 暂无评论