页面加载textarea后自动获取焦点,在页面加载的时,调用此方法,可使指定的表单控件得到焦点。
function setFocus(obj){
if(obj.setSelectionRange){
setTimeout(function(){
obj.setSelectionRange(0,0);
obj.focus();
},100);
}else{
if(obj.createTextRange){
var range=obj.createTextRange();
range.collapse(true);
range.moveEnd("character",0);
range.moveStart("character",0);
range.select();
}
try{obj.focus();}catch(e){}
}
}
function setFocus(obj){
if(obj.setSelectionRange){
setTimeout(function(){
obj.setSelectionRange(0,0);
obj.focus();
},100);
}else{
if(obj.createTextRange){
var range=obj.createTextRange();
range.collapse(true);
range.moveEnd("character",0);
range.moveStart("character",0);
range.select();
}
try{obj.focus();}catch(e){}
}
}
更多信息请查看IT技术专栏