在 tinymce 编辑器中获取选定的 html 内容 [英] Getting selected html content in tinymce editor
本文介绍了在 tinymce 编辑器中获取选定的 html 内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用此代码创建了一个自定义按钮
I have created a custom button using this code
setup : function(ed) {
ed.addButton('Tittle', {
title : 'Tittle',
image : './images/T.jpg',
onclick : function() {
ed.focus();
var c = ed.selection.getNode().nodeName;
if(c!="TITTLE")
{
ed.selection.setContent('<tittle>' + ed.selection.getContent() + '</tittle>');
}
else
{
}
}
});
当用户选择一个文本并点击新按钮时,我想在开头和结尾添加一个
标签,如果
标签不是他们的.如果 <tittle>
标签已经是他们在所选文本中的标签,我想删除标签
When a user select a text and click on the new button, i want to add a <title>
tag at beginning and ending, if <tittle>
tag is not their.If <tittle>
tag is already their in the selected text i want to remove the tag
推荐答案
try
selection.getContent({format : 'text'});
或
selection.getContent({format : 'html'});
http://www.tinymce.com/wiki.php/API3:method.tinymce.dom.Selection.getContent
要实现您想要的,您可以:
To achieve what you want you could do:
if(c!="TITTLE") {
node = ed.selection.getNode();
with(document.getElementById(iframe_id).contentWindow){
var newElement = document.createElement("tittle");
newElement.innerHTML = node.innerHTML;
}
node.parentNode.replaceChild(newElement, node);
}
else {
node = ed.selection.getNode();
with(document.getElementById(iframe_id).contentWindow){
var newElement = document.createTextNode(node.innerHTML);
}
node.parentNode.replaceChild(newElement, node);
}
这篇关于在 tinymce 编辑器中获取选定的 html 内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文