2
<div contenteditable="true" refs="input"></div>
keepLastIndex(ev) {
    console.log(ev)
    console.log(window.getSelection)
    console.log(document.selection)
    if (window.getSelection) { //ie11 10 9 ff safari
        ev.focus(); //解决ff不获取焦点无法定位问题
        var range = window.getSelection(); //创建range
        range.selectAllChildren(ev); //range 选择ev下所有子内容
        range.collapseToEnd(); //光标移至最后
    } else if (document.selection) { //ie10 9 8 7 6 5
        var range = document.selection.createRange(); //创建选择对象
        //var range = document.body.createTextRange();
        range.moveToElementText(ev); //range定位到ev
        range.collapse(false); //光标移至最后
        range.select();
    }
},

石头
19 声望1 粉丝