JS CKEditor Binding Click event after using SetData

Source: Internet
Author: User

CKEditor use SetData () will automatically lose the initial binding time, in Baidu found that there are many methods are wrong.

Recently in the project, due to customer needs, the original text format of the textarea tag changed to a rich text editor--ckeditor, plug-in use is very convenient, many online tutorials. The API looks more troublesome.

There are two ways to add a binding event to a text box:

1. CKEditor can be bound once when preloaded:

is code:

var a = Ckeditor.replace (ID);//ID is the ID value of the page element; Ckeditor_onfocus is a method of its own definition.
A.on ("Instanceready", function () {
This.document.on ("click", Function () {ckeditor_onfocus (id);});
});

The first method is easy to understand and binds the event when it starts initializing. Doing the right thing, but ckeditor. After using the assignment Method SetData (), the Click event of the initialization binding is automatically lost;

Therefore, after each use of the SetData () method to rebind the event, the two binding methods are not the same.

JS Code:

function Cke_setdata (ID,VA) {//ID is the ID value of the page element; VA is the content that needs to be assigned
ckeditor.instances["" +id+ ""].setdata (Va,function () {
  ckeditor.instances["+id+" "].on (" Focus ", function () {Ckeditor_onfocus (" "+id+" ");});
} );
}

Once you have re-bound, you can click again to implement the bound event effect.

When using CKEditor, be sure to pay attention to two ways to bind events.

JS CKEditor Binding Click event after using SetData

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.