兼容谷歌火狐-input光標位置
input框在沒有添加任何效果的情況下,輸入文字后光標始終在最后的位置,谷歌||火狐效果一樣
但是在給input加入點擊事件后 谷歌:input框插入文字后,光標會自動到最后位置
火狐:input框插入文字后,光標在插入文字的后面
兼容:光標在文字的最后面
function moveEnd(obj){
obj.focus();
var len = obj.value.length;
if (document.selection) {
var sel = obj.createTextRange();
sel.moveStart('character',len);
sel.collapse();
sel.select();
} else if (typeof obj.selectionStart == 'number' && typeof obj.selectionEnd == 'number') {
obj.selectionStart = obj.selectionEnd = len;
}
}

兼容:光標在中間插入文字的后面
function moveEnd(obj){
obj.focus();
var len = obj.value.length;
if (document.selection) {
var sel = obj.createTextRange();
sel.moveStart('character',len);
sel.collapse();
sel.select();
} else if (typeof obj.selectionStart == 'number' && typeof obj.selectionEnd == 'number') {
setCursorPosition(obj,obj.selectionStart)
}
}
設置光標位置:
setSelectionRange(obj.selectionStart,obj.selectionStart);
selectionStart
輸入性元素selection起點的位置,可讀寫。
selectionEnd
輸入性元素selection結束點的位置,可讀寫。
setSelectionRange(start, end)
設置輸入性元素selectionStart和selectionEnd值
輸入性元素selection起點的位置,可讀寫。
selectionEnd
輸入性元素selection結束點的位置,可讀寫。
setSelectionRange(start, end)
設置輸入性元素selectionStart和selectionEnd值
