87,903
社区成员
发帖
与我相关
我的任务
分享
var iframe = document.getElementById(jeditor.InstanceName);
var iframeDocument = iframe.contentDocument
|| iframe.contentWindow.document;
$(iframeDocument)
.bind(
"mouseup",
function() {
var editor = document.getElementById(jeditor.InstanceName);
editor.focus();
jeditor.Range = editor.contentWindow.document.selection.createRange();//保存路径
});
function insertText (text) {
if (document.all){
jeditor.Range.select(); //无论是否选择了内容,都能使光标回到原来的位置
jeditor.Range.pasteHTML(text);
}else{
var editor = document.getElementById(jeditor.InstanceName);
editor.focus();
var rng = editor.contentWindow.getSelection().getRangeAt(0);
var frg = rng.createContextualFragment(text);
rng.insertNode(frg);
}
};
IE, FF下测试通过