使用Jquery从CKEditor检测onChange事件 [英] Detecting onChange events from a CKEditor using Jquery

查看:311
本文介绍了使用Jquery从CKEditor检测onChange事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CKEditor和jQuery,我想在用户更改字段的值时将标记切换为true。所有具有wysiwyg类的文本区域被转换为CKEditors,但不知何故, $(' .wysiwyg')。change()事件从未被检测到。我做了一些谷歌搜索,但关键字组合似乎只是不相关的结果(我的google-fu吮吸)。



感谢任何帮助:)



编辑:

  for(var i in CKEDITOR.instances){
CKEDITOR.instances [i] .on('click',function(){alert('test 1 2 3')});
}

我试过上面的代码,它不工作。它不给我一个错误,意味着它找到CKEditor对象,但由于某种原因,监听器不附加到它?



此外,如果我更换事件附件与只是警报(CKEDITOR.instances [i] .name); 它会警告我的textarea的名称,所以我知道我不尝试附加点击事件to nothing:)

解决方案

你可以在这篇文章中得到一个插件(以及关于什么东西被检测为变化的解释) http://alfonsoml.blogspot.com/2011/03/onchange-event-for- ckeditor.html ,以便您可以执行

 (CKEDITOR.instances中的var i){
CKEDITOR.instances [i] .on('change',function(){alert('test 1 2 3')});
}


I'm working with the CKEditor and jQuery and I'd like to toggle a flag to true whenever a user changes the value of a field. One of those fields is a CKEditor instance.

All the textareas that have the "wysiwyg" class get converted to CKEditors but somehow the $('.wysiwyg').change() event never gets detected. I did some googling but the keyword combination seems to bring up nothing but irrelevant results (my google-fu sucks).

Thanks for any help :)

Edit:

for (var i in CKEDITOR.instances) {
        CKEDITOR.instances[i].on('click', function() {alert('test 1 2 3')});
    }

I tried the code above and it doesn't work. It doesn't give me an error meaning that it finds the CKEditor objects but for some reason the listener isn't attached to it?

Also, if I replace the event attachment with just alert(CKEDITOR.instances[i].name); it'll alert the name of my textarea so I know I'm not trying to attach the click event to nothing :)

解决方案

You can get a plugin (and an explanation about what things are detected as changes) in this post: http://alfonsoml.blogspot.com/2011/03/onchange-event-for-ckeditor.html so you can do things like

for (var i in CKEDITOR.instances) {
        CKEDITOR.instances[i].on('change', function() {alert('test 1 2 3')});
    }

这篇关于使用Jquery从CKEditor检测onChange事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆