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