光标选中,兼容IE FIREFOX CHROME

//光标选中,兼容IE FF chrome
function focusAll(id){
	var el = $(id);
	var len = el.value.length;
	focus(id,0,len);
}
function focus(id,start,end){
	var el = $(id);
	if(el.createTextRange){
		var Range=el.createTextRange();
		Range.collapse();
		Range.moveEnd('character',end);
		Range.moveStart('character',start);
		Range.select();
	}
	else if(el.setSelectionRange){
        el.focus();  
        el.setSelectionRange(start,end);  //设光标 
    }
}

相关推荐