1

H7i の皆さん、TinyMce エディタで奇妙な問題が発生しています。私がやろうとしているのは、テキストを選択し、ボタンをクリックして、最初と最後にタグを追加することです。

たとえば、元のテキストが の<p>hello</p>場合、終了テキストは になります<myTag><p>hello</p></myTag>

正常に動作しますが、1 行のテキストを選択すると、既存のタグが返されません。したがって、前の例では、helloonly を取得し、notを取得し<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

何か助けはありますか?

4

2 に答える 2

1

ユーザーが選択したコンテンツに応じて、コンテンツを取得するためにさまざまな関数を使用する必要があります。

var node = ed.selection.getNode();

if (node.nodeName != 'P' )
{
     content = ed.selection.getContent();
}
else content = node.outerHtml;
于 2012-10-11T07:29:05.643 に答える