3个回答
2013-07-20
展开全部
var MyEditorID = ""; //是否开启设计模式
function EditorDesignMode(EditorID)
{
var deditor = document.getElementById(EditorID+"_iframe").contentWindow;
deditor.document.designMode="on";
//deditor.contentEditable="true";
deditor.document.open();
deditor.document.writeln("<html><head><title></title></head><body></body></html>");
deditor.document.close(); MyEditorID = EditorID+"_iframe";
deditor.document.body.onclick =GetPos;
deditor.document.body.onselect =GetPos;
deditor.document.body.onkeyup =GetPos;
} function GetPos()
{
var deditor = document.getElementById(MyEditorID).contentWindow;
deditor.pos = deditor.document.selection.createRange();
//alert("dafd");
} //插入图片至编辑器
function InsertsImageGo(imageurl,EditorID)
{
var deditor = document.getElementById(EditorID+"_iframe").contentWindow;
// 聚焦编辑器
deditor.focus();
//插入图片处理
if(imageurl != "")
{
if (window.navigator.userAgent.indexOf("MSIE")<1)
{
deditor.document.execCommand('InsertImage',false,imageurl);
}
else
{
var _image = document.createElement("img");
_image.src=imageurl;
_image.border="0"; if (deditor.document.selection.type.toLowerCase() != "none")
{
deditor.document.selection.clear() ;
}
deditor.pos.pasteHTML(_image.outerHTML);
}
}
// 聚焦编辑器
deditor.focus();
HideDiv("PopDiv");
}在iframe里加上onclick,onselect,onkeyup事件,并保存当前的焦点,再插入的时候在刚才保存的焦点处插入就可以了
function EditorDesignMode(EditorID)
{
var deditor = document.getElementById(EditorID+"_iframe").contentWindow;
deditor.document.designMode="on";
//deditor.contentEditable="true";
deditor.document.open();
deditor.document.writeln("<html><head><title></title></head><body></body></html>");
deditor.document.close(); MyEditorID = EditorID+"_iframe";
deditor.document.body.onclick =GetPos;
deditor.document.body.onselect =GetPos;
deditor.document.body.onkeyup =GetPos;
} function GetPos()
{
var deditor = document.getElementById(MyEditorID).contentWindow;
deditor.pos = deditor.document.selection.createRange();
//alert("dafd");
} //插入图片至编辑器
function InsertsImageGo(imageurl,EditorID)
{
var deditor = document.getElementById(EditorID+"_iframe").contentWindow;
// 聚焦编辑器
deditor.focus();
//插入图片处理
if(imageurl != "")
{
if (window.navigator.userAgent.indexOf("MSIE")<1)
{
deditor.document.execCommand('InsertImage',false,imageurl);
}
else
{
var _image = document.createElement("img");
_image.src=imageurl;
_image.border="0"; if (deditor.document.selection.type.toLowerCase() != "none")
{
deditor.document.selection.clear() ;
}
deditor.pos.pasteHTML(_image.outerHTML);
}
}
// 聚焦编辑器
deditor.focus();
HideDiv("PopDiv");
}在iframe里加上onclick,onselect,onkeyup事件,并保存当前的焦点,再插入的时候在刚才保存的焦点处插入就可以了
2013-07-20
展开全部
html页面中有
<iframe id="edi" ></iframe>
<input id="text1" type="text" />
<input id="ok" type="button" value="确定" />
<iframe id="edi" ></iframe>
<input id="text1" type="text" />
<input id="ok" type="button" value="确定" />
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-20
展开全部
利用id名.focus实现!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询