我有一个 iframe 对象,里面有一个 contenteditable 主体。我想在插入符号位置粘贴一些文本或 html 元素。我尝试了这段代码,但出现错误无法读取未定义的属性“createRange”
$('#edit_frame').selection.createRange().pasteHTML($('<span>text</span>'));
最佳答案
因为您需要获取 iFrame 的文档。
// HTML selected
document.getElementById('edit_frame').contentWindow.document.selection.createRange().htmlText;
但仅限 IE。阅读@Tim Down 答案:https://stackoverflow.com/a/6668159/2389232 .
我也修改了该函数来获取 iFrame 的选择 HTML。请参阅http://jsfiddle.net/4bp42891/ .
关于javascript - 在框架的可内容编辑主体内的插入符号位置插入文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25304399/