问题
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