W. *_*sen 1 javascript jquery internet-explorer range
有一个div:<div contenteditable="true"></div>在IE(7,8,9)中,然后我单击一个按钮以使用该document.execCommand('insertImage')方法插入图像.然后插入图像.到现在为止没有问题.但是使用可调整大小的处理程序选择插入的图像.如何取消选择并重新聚焦图像?谢谢.
$button.click(function(){
document.execCommand("insertImage",false,'url');
});
更新了更简单的代码
这是一些讨厌的代码来做到这一点.在其他浏览器中,它似乎无论如何都可以工作,因此可以按原样使用以下内容.
演示: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");
}
}
Run Code Online (Sandbox Code Playgroud)