TinyMCE - 未捕获TypeError:wc [0] .removeClass不是函数

时间:2016-01-12 12:11:07

标签: javascript tinymce tinymce-plugins

This TinyMCE plugin从wordcount插件分叉,当字符数超过设置限制时也会显示错误消息。但它没有用。每次更新操作addClassremoveClass功能都无法找到。我对代码略有编辑,但核心是相同的:

// 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

1 个答案:

答案 0 :(得分:1)

我认为删除答案包含了这个的关键。

wc[0]包含一个有效的dom元素,但removeClasse不是你可以在这样一个元素上调用的有效函数(至少不使用jQuery)。

如果没有jQuery,您可以尝试以下方法:

而不是调用removeClass使用

wc[0].setAttribute('class', '');

而不是调用addClass使用

wc[0].setAttribute('class', 'danger');

这有点简化,但是如果你没有在wc[0]元素中使用任何其他类,它应该没问题。