我正在使用Redactor WYSIWYG editor编辑我的内容。如何检查某个元素是否已经初始化了redactor?我目前正在检查元素是否有类名redactor-editor,但我猜肯定有更好的方法?
$('.btn-edit-content').click(function(e){
e.preventDefault();
if(!$($(this).attr('href')).hasClass('redactor-editor'))
$($(this).attr('href')).redactor({
toolbarFixedTopOffset: 95,
plugins: ['table']
});
})发布于 2015-06-22 19:16:42
根据他们的api文档,您可以这样做
$('.btn-edit-content').click(function(e){
e.preventDefault();
if( $.data($($(this).attr('href'))[0], 'redactor') === undefined) {
$($(this).attr('href')).redactor({
toolbarFixedTopOffset: 95,
plugins: ['table']
});
}
});Look at their doc for more help
希望它能帮到你
发布于 2016-04-20 19:07:34
我还没有找到更好的方法,所以我正在检查Redactor是否以这种方式初始化(代码片段在coffeescript中):
$('.redactor').each ->
$editor = $(this).siblings('.redactor-editor')
$(this).redactor() unless $editor.length上下文:我在一个页面上有几个.redactor类的文本区域,在某些时候,它们中的一些丢失了Redactor的初始化。如果我只是一次为所有的文本区域调用.redactor(),那么之前初始化的Redactor就会被复制。
https://stackoverflow.com/questions/30978223
复制相似问题