TinyMce editor not returning tags

浪尽此生 提交于 2019-12-14 02:33:52

问题


H7i guys, I am having a weird problem with the TinyMce editor. What I am trying to do is to select some text, click a button and append a tag at the start and at the end.

For example, if the original text is <p>hello</p>, the end text would be <myTag><p>hello</p></myTag>.

It works fine but when selecting a single line of text the existing tags are not returned. So in the previous example I would get hello only and not <p>hello</p>.

When I select multiple lines it returns the tags.

Here is what I have tried so far:

            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

Any help?


回答1:


You will need to employ different functions to get the content, depending on the content the user selected

var node = ed.selection.getNode();

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



回答2:


I use this, and works well:

var textt= tinyMCE.activeEditor.selection.getContent({format : 'text'});
alert(textt);

BUT NOTE: You should not select text from the start of a paragraph to the end of a paragraph,

because in that case(maybe bug of TinyMce), it cant get content .



来源:https://stackoverflow.com/questions/12825464/tinymce-editor-not-returning-tags

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