javascript TinyMCE,允许数据属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7744903/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 01:08:58  来源:igfitidea点击:

TinyMCE, allow data attribute

javascripthtmlattributestinymcerte

提问by FMaz008

I have to use the HTML 5 data attributein Tiny MCE, but the editor always clear them, as it's not an attribute known by the default valid_elementsconfiguration.

我必须在 Tiny MCE 中使用 HTML 5数据属性,但编辑器总是清除它们,因为它不是默认valid_elements配置已知的属性。

So I have 2 problems here:

所以我在这里有两个问题:

  • the data attribute is dynamic ( it could be data-options, data-test, data-foo, etc... ) So I would need a wildcard value or something.
  • I want to allow the data attribute for all tags.
  • 数据属性是动态的(它可以是数据选项、数据测试、数据 foo 等...)所以我需要一个通配符值或其他东西。
  • 我想允许所有标签的数据属性。

So far, I've tried:

到目前为止,我已经尝试过:

extended_valid_elements : '@[id|class|title|style|data-options]',

And:

和:

extended_valid_elements : '*[id|class|title|style|data*]',

But it doesn't work :(

但它不起作用:(

回答by Thariama

extended_valid_elementsis not the best choice here. Hava a look at the valid_elementssetting. Here is an example

extended_valid_elements不是这里的最佳选择。哈瓦看看valid_elements设置。这是一个例子

    // The valid_elements option defines which elements will remain in the edited text when the editor saves.
    valid_elements: "@[id|class|title|style|data-options|data*]," +
    "a[name|href|target|title]," +
    "#p,-ol,-ul,-li,br,img[src|height|width],-b,-i,-u," +
    "-span[data-mce-type],hr",

回答by s k

I am using:

我在用:

extended_valid_elements: "+@[data-options]"

and it works for me. (TinyMCE 4.3.11. Notice the + sign?)

它对我有用。(TinyMCE 4.3.11。注意到+号了吗?)