javascript TinyMCE 返回没有 HTML 的内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14872569/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TinyMCE return content without HTML
提问by Nehal
I am using an inline editor ipweditortool which internally use tinyMCE editor. On their demo page it is using old version of tinyMCE which is not working in my IE. So I updated tinyMCE with latest version.
我正在使用内联编辑器ipweditor工具,该工具在内部使用 tinyMCE 编辑器。在他们的演示页面上,它使用的是旧版本的 tinyMCE,它在我的 IE 中不起作用。所以我用最新版本更新了 tinyMCE。
In old version of TinyMCE it was returning me defined content with all the HTML tags, while in new version it is returning me only text without HTML tags. Here is the link of jsFiddle demo. Anyone know how do I configure tinyMCE so it return me HTML tags also.
在旧版本的 TinyMCE 中,它返回我定义的所有 HTML 标签的内容,而在新版本中,它只返回没有 HTML 标签的文本。这是 jsFiddle演示的链接。任何人都知道如何配置 tinyMCE,以便它也返回 HTML 标签。
HTML
HTML
<div style="display:none">
<form method="post" action="somepage">
<textarea name="content" style="width:100%"></textarea>
</form>
</div>
<div style="border: solid thin gray; padding:5px;">
<div class="my_text"><b> <span>Click me! I am editable and WYSIWYG!!!</span></b>
</div>
Javascript
Javascript
$(document).ready(function () {
var ed = new tinymce.Editor('content', {
mode: "exact",
theme: "advanced",
plugins: "emotions,table",
theme_advanced_toolbar_location: "top",
theme_advanced_statusbar_location: "bottom",
theme_advanced_resizing: true,
theme_advanced_buttons1: "bold,italic,underline,fontselect,fontsizeselect,forecolor,backcolor,|,code,",
theme_advanced_buttons2: "",
theme_advanced_buttons3: "",
table_default_cellspacing: 0,
table_default_border: 1,
remove_linebreaks: false
});
$('.my_text').editable({
type: 'wysiwyg',
editor: ed,
onSubmit: function submitData(content) {
alert(content.current);
},
submit: 'save',
cancel: 'cancel'
});
});
回答by Nehal
It's always not preferable to make any modification in plugin library, but this really need some modification. The problem was with 'ipweditor.js' tool. It's creating new tinyMCE editor object internally and getting response in "text" format from tinyMCE.
在插件库中进行任何修改总是不可取的,但这确实需要一些修改。问题出在“ipweditor.js”工具上。它正在内部创建新的 tinyMCE 编辑器对象,并从 tinyMCE 以“文本”格式获取响应。
var r =options.editor.getContent({format : 'text'});
We need to replace 'text' with 'html'
我们需要用 'html' 替换 'text'
var r =options.editor.getContent({format : 'html'});
It's more preferable to make this format setting also dynamic so append a setting variable in inital settings and fetch value from there.
最好使这种格式设置也是动态的,因此在初始设置中附加一个设置变量并从那里获取值。
var defaults = {
onEdit: null,
onSubmit: null,
onCancel: null,
editClass: null,
submit: null,
cancel: null,
type: 'text', //text, textarea or select
submitBy: 'blur', //blur,change,dblclick,click
editBy: 'click',
editor: 'non',
options: null,
format:'text'
}
var options = $.extend(defaults, options);
and now retrieve using the format defined in setting.
现在使用设置中定义的格式进行检索。
var r =options.editor.getContent({format : options.format});