如何在IE中插入图像的可疑DIV中重新聚焦? [英] how refocus when insert image in contenteditable DIVs in IE?

查看:115
本文介绍了如何在IE中插入图像的可疑DIV中重新聚焦?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在IE(7,8,9)中有一个div:< div contenteditable =true>< / div> ,然后我点击了按钮使用 document.execCommand('insertImage')方法插入图像。然后插入图像。到现在为止没有问题。
但是使用可调整大小的处理程序选择插入的图像。如何取消选择并重新聚焦图像?
谢谢。

There is a div: <div contenteditable="true"></div> in IE(7,8,9), then I click a button to insert an image with using the document.execCommand('insertImage') method. Then the image was inserted. Until now there is no problem. But the inserted image is selected with resizable handlers. How could I cancel the selection and refocus behind the image? Thanks.

$ button.click(function(){
document.execCommand(insertImage,false, 'url');
});

推荐答案

使用更简单的代码更新

这里有一些令人讨厌的代码。在其他浏览器中,它似乎仍然有效,因此可以按原样使用以下内容。

Here's some nasty code to do this. In other browsers, it seems to work anyway, so the following can be used as it is.

演示: http://jsfiddle.net/timdown/mr7Ac/6/

代码:

function insertImage() {
    var sel = document.selection;
    if (sel) {
        var textRange = sel.createRange();
        document.execCommand('insertImage', false, "someimage.png");
        textRange.collapse(false);
        textRange.select();
    } else {
        document.execCommand('insertImage', false, "someimage.png");
    }
}

这篇关于如何在IE中插入图像的可疑DIV中重新聚焦?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆