【发布时间】:2016-01-12 12:11:07
【问题描述】:
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
【问题讨论】:
-
editor.theme.panel.find('#maxlength') 是一个有效的 dom 元素吗?
-
尝试记录 wc 变量并查看它包含的内容。除此之外,请确保 jQuery 已正确加载:)
-
@Thariama 是的,是的。
-
@Ynhockey,请查看我对问题的编辑。
标签: javascript tinymce tinymce-plugins