頁面加載textarea后自動(dòng)獲取焦點(diǎn),在頁面加載的時(shí),調(diào)用此方法,可使指定的表單控件得到焦點(diǎn)。
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技術(shù)專欄