This TinyMCE plugin从wordcount插件分叉,当字符数超过设置限制时也会显示错误消息。但它没有用。每次更新操作addClass
和removeClass
功能都无法找到。我对代码略有编辑,但核心是相同的:
// on init
var statusbar = editor.theme.panel && editor.theme.panel.find('#statusbar')[0];
if (statusbar) {
tinymce.util.Delay.setEditorTimeout(editor, function() {
statusbar.insert({
type: 'label',
name: 'maxlength',
text: ['Length: {0}', self.getCharCount()],
classes: 'wordcount',
disabled: editor.settings.readonly
}, 0);
...
// on update
var wc = editor.theme.panel.find('#maxlength');
wc[0].removeClass('danger'); // Error!
如何解决?
编辑: console.log(wc[0])
输出:
t {_super: undefined, settings: Object, _id: "mceu_160", _aria: Object, _elmCache: Object…}
$: function f(e,t)
arguments: [Exception: TypeError: 'caller' and 'arguments' are restricted function properties and cannot be accessed in this context...]
attrHooks: Object
caller: [Exception: TypeError: 'caller' and 'arguments' are restricted function properties and cannot be accessed in this context...]
contains: function (e,t)
cssHooks: Object
each: function m(e,t)
expr: Object
extend: function s(e,n)
filter: function (e,t,n)
find: function e(e,t,n,r)
fn: f[0]
grep: function g(e,t)
inArray: function h(e,t)
isArray: function isArray()
length: 2
makeArray: function (e)
name: "f"
overrideDefaults: function (e)
prototype: f[0]
text: function (e)
trim: function p(e)
unique: function (e)
__proto__: function ()
<function scope>
$el: f.fn.f.init[1]
_aria: Object
_elmCache: Object
_eventDispatcher: t
_eventsRoot: t
_id: "mceu_160"
_name: "wordcount"
_nativeEvents: Object
_parent: t
_super: undefined
borderBox: undefined
canFocus: false
classes: n
data: t
marginBox: undefined
paddingBox: undefined
rootControl: t
settings: Object
state: t
type: "label"
__proto__: t
答案 0 :(得分:1)
我认为删除答案包含了这个的关键。
wc[0]
包含一个有效的dom元素,但removeClasse
不是你可以在这样一个元素上调用的有效函数(至少不使用jQuery)。
如果没有jQuery,您可以尝试以下方法:
而不是调用removeClass
使用
wc[0].setAttribute('class', '');
而不是调用addClass
使用
wc[0].setAttribute('class', 'danger');
这有点简化,但是如果你没有在wc[0]
元素中使用任何其他类,它应该没问题。