各位,我在TinyMce编辑器中遇到了一个奇怪的问题。我想做的是选择一些文本,单击一个按钮,然后在开头和结尾处添加标签。

例如,如果原始文本为<p>hello</p>,则结束文本为<myTag><p>hello</p></myTag>

它工作正常,但是当选择一行文本时,不会返回现有标签。因此,在前面的示例中,我只会得到hello而不是<p>hello</p>

当我选择多行时,它将返回标签。

到目前为止,这是我尝试过的:

            var se = ed.selection.getContent(); //Doesn't return tags on single line
            var be = ed.selection.getNode().outerHtml; //Doesn't work with multiline
            var ke = ed.selection.getContent({ format: 'raw' }); //Same as the first option


有什么帮助吗?

最佳答案

您将需要采用不同的功能来获取内容,具体取决于用户选择的内容

var node = ed.selection.getNode();

if (node.nodeName != 'P' )
{
     content = ed.selection.getContent();
}
else content = node.outerHtml;

关于javascript - TinyMce编辑器未返回标签,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12825464/

10-12 13:16