Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tinymce将标题样式应用于整个段落,而不仅仅是选定的文本_Tinymce - Fatal编程技术网

Tinymce将标题样式应用于整个段落,而不仅仅是选定的文本

Tinymce将标题样式应用于整个段落,而不仅仅是选定的文本,tinymce,Tinymce,我刚刚注意到TinyMCE编辑的一个恼人行为。当我写了,比方说,几段文字,我想选择其中的一些并将其作为标题(标题2样式),整个文字都会得到标题样式,而不仅仅是我选择的文字 当我想使用粗体字时,这种情况不会发生——在这种情况下,它的效果与预期的一样;只有选定的文本变为粗体 我如何改变这种行为?我知道有HTML模式可以改变样式,但我担心我的客户对HTML不是很熟悉,他们只想使用视觉模式。我想这是因为h2标记通常不能作为段落的子节点。 您可以根据需要尝试调整tinymce配置参数。这是tinymce的

我刚刚注意到TinyMCE编辑的一个恼人行为。当我写了,比方说,几段文字,我想选择其中的一些并将其作为标题(标题2样式),整个文字都会得到标题样式,而不仅仅是我选择的文字

当我想使用粗体字时,这种情况不会发生——在这种情况下,它的效果与预期的一样;只有选定的文本变为粗体


我如何改变这种行为?我知道有HTML模式可以改变样式,但我担心我的客户对HTML不是很熟悉,他们只想使用视觉模式。

我想这是因为h2标记通常不能作为段落的子节点。
您可以根据需要尝试调整tinymce配置参数。

这是tinymce的固有行为,无法更改。

以下是我找到的解决方法。对我来说很有用

tinyMCE.PluginManager.add('FormatingToolbarButtons', function (editor, url) {
['pre', 'p', 'code', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'].forEach(function (name) {
    editor.addButton("style-" + name, {
        tooltip: "Toggle " + name,
        text: name.toUpperCase(),
        onClick: function () {
            if (this.active()) {
                editor.execCommand('mceToggleFormat', false, name);
                this.active(false)
            }
            else {
                editor.selection.setContent('<' + name + '>' + editor.selection.getContent() + '</' + name + '>');
                this.active(true)
            }
        },
        onPostRender: function () {
            var self = this, setup = function () {
                editor.formatter.formatChanged(name, function (state) {
                    self.active(state);
                });
            };
            editor.formatter ? setup() : editor.on('init', setup);
        }
    })
});
tinyMCE.PluginManager.add('FormatingToolbarButtons',函数(编辑器,url){
['pre','p','code','h1','h2','h3','h4','h5','h6']{
editor.addButton(“样式-”+名称{
工具提示:“切换”+名称,
text:name.toUpperCase(),
onClick:function(){
if(this.active()){
execCommand('mcetogleformat',false,name);
此参数为.active(false)
}
否则{
editor.selection.setContent(“”+editor.selection.getContent()+“”);
此。活动(真)
}
},
onPostRender:函数(){
var self=this,setup=function(){
editor.formatter.formatChanged(名称、函数(状态){
自激活(状态);
});
};
editor.formatter?setup():editor.on('init',setup);
}
})
});

}))

在点击标题样式之前,您必须将标题文本移动到它自己的段落中。