在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
{
}
}
});
当用户选择文本并单击新按钮时,我想添加一个<$ c如果< tittle>
标签不是它们的,则为$ c>< title> 标签。如果 < 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屋!
查看全文