我到处都在寻找解决方案,但没有找到答案,所以你是我最后的希望,Stackoverflow...
关于 cleditor,有人知道如何在“查看源代码”模式下使用“inserthtml”命令吗?
目前,我有一个方法附加到按钮的 onclick 处理程序,将一个字符串插入到 cleditor 的文本区域中:
editor.focus();
setTimeout(function() { editor.execCommand('inserthtml', stringToInsert); }, 0);
上面的代码在正常的 Rich Text 模式下运行良好,但如果您尝试在 View Source 模式下执行它,则会发生以下情况:
- 在 Firefox 中,它会弹出一条小消息,提示“执行错误 inserthtml 命令。”
- 在 Chrome 中,它会自动失败
- 在 IE 中:
- 如果文本区域为空,我在 Visual Studio 中的“y(a).pasteHTML(c)”处打断点,看起来像 jquery.cleditor.min.js,并显示以下消息“Microsoft JScript 运行时错误: 未指定的错误。”
- 如果文本区域已经包含文本,我会在同一文件中的“a.range[0].select()”处设置断点,并显示以下消息“Microsoft JScript 运行时错误:由于错误无法完成操作800a025e。”
最佳答案
嗨,我认为这是与 here 非常相似的问题
我假设您粘贴的代码是在按钮点击功能中执行的 在这个函数的末尾添加
返回错误;
添加类似这样的东西:
函数 someClick(e, 数据) {
// Get the editor
var editor = data.editor;
editor.focus();
setTimeout(function() { editor.execCommand('inserthtml', stringToInsert); }, 0);
return false;
编辑:
是的,你是对的,这并不容易:当你处于正常模式时,你的文本区域实际上是 iframe 当你处于源代码模式时,你的 textarea 再次成为 textarea 所以要编辑里面的数据你可以通过
$('#mytextarea').val()
如果你想在最后添加一些东西,你可以使用:
setTimeout(function() {$('#mytextarea').val($('#mytextarea').val()+'aaaaa') }, 3000);
如果您想在当前位置插入,这应该会有所帮助:Cursor position in a textarea (character index, not x/y coordinates)
关于javascript - 在 "Error executing the insertHtml command"模式下插入 html 时 cleditor 中出现 "View Source"消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9223467/