Internet explorer 在Internet Explorer 9中使用cleditor会导致双引号被错误转义
我在互联网上搜寻这个问题的答案,但是,唉,我不得不寻求帮助 我使用jQuery插件来实现其富文本/HTML编辑功能。在大多数情况下,它运行良好。但是,如果我在IE9中执行以下操作,就会出现一个奇怪的问题:Internet explorer 在Internet Explorer 9中使用cleditor会导致双引号被错误转义,internet-explorer,internet-explorer-9,cleditor,Internet Explorer,Internet Explorer 9,Cleditor,我在互联网上搜寻这个问题的答案,但是,唉,我不得不寻求帮助 我使用jQuery插件来实现其富文本/HTML编辑功能。在大多数情况下,它运行良好。但是,如果我在IE9中执行以下操作,就会出现一个奇怪的问题: 单击工具栏右上角的“显示源代码”按钮切换到HTML模式 粘贴以下代码段: <p>Note the double-quotes</p> <div onclick='alert("hi")'>click me</div> 请注意双引号 点击我 切
<p>Note the double-quotes</p>
<div onclick='alert("hi")'>click me</div>
请注意双引号
点击我
<div onclick="alert(\"hi\")">click me</div>
<div onclick="alert("hi")">click me</div>
点击我
这到底是怎么回事?其他浏览器会像这样正确地转义双引号:
<div onclick="alert(\"hi\")">click me</div>
<div onclick="alert("hi")">click me</div>
点击我
我自己也尝试过使用实体,
“
,但没关系——IE9仍然把它搞砸了。有人知道如何克服这个问题吗?没关系,我想我知道了。如果有人在这个问题上挣扎,我想这是使用cleditor、XHTML插件和Internet Explorer的组合
您可以通过在cleditor代码之前添加以下JavaScript片段来修复此问题:
(function ($) {
var oldCallback = $.cleditor.defaultOptions.updateTextArea;
$.cleditor.defaultOptions.updateTextArea = function (html) {
if (oldCallback) {
html = oldCallback(html);
}
var isIE = /*@cc_on!@*/false;
if (isIE) {
return html.replace(/\\\"/g, """);
} else {
return html;
}
};
})(jQuery);
或者,您可以在jquery.cleditor.js中执行条件替换(cleditor v1.3.0的第1126行)