How to Toggle / remove classes in wysihtml5

六眼飞鱼酱① 提交于 2019-12-11 07:35:53

问题


I need to be able remove the previous class from a span when adding a new one.

Below is the custom function which adds a span and a class that gets passed through the button.

wysihtml5.commands.custom_underline = {
  exec: function(composer, command, className) {
    return wysihtml5.commands.formatInline.exec(composer, command, "span", className, new RegExp(className, "g"));
  },
  state: function(composer, command, className) {
    return wysihtml5.commands.formatInline.state(composer, command, "span", className, new RegExp(className, "g"));
  }
};

Here are the buttons:

<a data-wysihtml5-command="custom_underline" data-wysihtml5-command-value="u grey">Grey</a>
<a data-wysihtml5-command="custom_underline" data-wysihtml5-command-value="u dark_grey">Dark Grey</a>
<a data-wysihtml5-command="custom_underline" data-wysihtml5-command-value="u black">Black</a>

If I click on both the grey and dark grey buttons it produces the following code:

<span class="u grey u dark_grey">Some text</span>

I need to find some way to remove the previous class before adding the new one.

来源:https://stackoverflow.com/questions/15906030/how-to-toggle-remove-classes-in-wysihtml5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!