[TinyMCE] 关于 TinyMCE 显示 Html 卷标错误的问题

arthurbonnie1977 arthurbonnie1977 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
你好,我的网页有崁入 TinyMCE 这个 HTML 富文本编辑器。
TinyMCE 版本是 2,1

我有一个 HTML 档案的原始码如下


<p><span style="color: #ff0000;"><strong><span style="font-size: xx-large;">Hello</span></strong></span> <span style="color: #ff6600;"><em><span style="font-size: x-large;">TinyMCE</span></em></span> <span style="text-decoration: underline; color: #3366ff;"><span style="font-size: large;">Test</span></span> 01</p>


我如果从 javascript 程序中从 Server 中读取档案再用 TinyMCE显示,
就无法显示有关字体的颜色与大小。

但是我如果先在 TinyMCE 中按下 "Html" 的按键,也就是用 html 原始码编辑;
然后把这一段 HTML 的原始码贴上去,就一切正常。

我的 TinyMCE 在 javascript 中的初始化程序代码如下:


tinyMCE.init({
language: "zh-tw",

theme: "advanced",
*/
mode: "textareas",
skins: "o2k7",

elements: "txtContent",

element_format: "html",
schema: "html4",

valid_elements: "*
  • ",

    // Location of TinyMCE script
    script_url: '/Resource/Package/TinyMCE/3x/jscripts/tiny_mce/tiny_mce.js',

    // General options
    theme: "advanced",
    plugins: "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist",

    // Theme options

    theme_advanced_buttons1: "save,newdocument,
  • |,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
    theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
    theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
    theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
    theme_advanced_toolbar_location: "top",
    theme_advanced_toolbar_align: "left",
    theme_advanced_statusbar_location: "bottom",
    theme_advanced_resizing: true,

    template_external_list_url: "/Resource/Package/TinyMCE/3x/jscripts/tiny_mce/plugins/lists/template_list.js",
    external_link_list_url: "/Resource/Package/TinyMCE/3x/jscripts/tiny_mce/plugins/lists/link_list.js",
    external_image_list_url: "/Resource/Package/TinyMCE/3x/jscripts/tiny_mce/plugins/lists/image_list.js",
    media_external_list_url: "/Resource/Package/TinyMCE/3x/jscripts/tiny_mce/plugins/lists/media_list.js"


    });


关于从服务器端取回 html 的 javascript 程序代码 如下


$.ajax({
type: "POST",
url: "http://網頁的網址",
data: "",
contentType: "application/json",
dataType: "text",

beforeSend: function (XHR) {
},
complete: function (XHR, TS) {
},
success: function (data) {
var rs = JSON.parse(data);
window.alert(rs.d);
tinyMCE.activeEditor.setContent(rs.d);
window.alert("Success Ajax");
},
error: function (data) {
alert("error :" + data);
}
});


在 上面这一段程序代码中的 success 返回处里函式中, window.alert(rs.d) 都还是和原始来源的 html 一样,有包含字体颜色和大小的 html 标签。

但是再透过 tinyMCE.activeEditor.setContent(rs.d) 这一行程序代码之后,在 TinyMCE 显示出来的就自动把字体的大小和颜色都去除了。

但是奇怪的是,还是有包含粗体字的 <strong> 标签。

我把 TinyMCE 显示的 html 码贴在下面,你会发现 TinyMCE 自动把 <span style=""> 这样的标签去除了。


<p>"</p>
<p><span ff0000=""><strong><span xx-large="">Hello</span></strong></span> <span ff6600=""><em><span x-large="">Justin</span></em></span> <span underline="" color:="" 3366ff=""><span large="">Test</span></span> 01</p>
<p>"</p>


更怪的是还自动的在整段的 html 码签后自动加上 " 的双引号。
有人知道该如何解决这个问题,让带有 css 属性的卷标恢复正常显示吗?
感谢帮忙。
...全文
评论
收藏 已收藏
分享
返回顶部
arthurbonnie1977
JavaScript 87,983 成员 224,681 内容