jquery 实现 input 内容全选

话不多说,奉上代码,用的jquery 1.11 ,考虑到要满足IE浏览器,所以写得有点长。如何简化写法,还望各位前辈多多指点!

// <选中输入框,内容全选>

$(function(){
ua=navigator.userAgent
ua=ua.toLocaleLowerCase()
browserType=""
if(ua.match(/msie/)!=null){
browserType="IE"
    }else if(ua.match(/firefox/)!=null){
browserType="火狐"
    }else if(ua.match(/opera/)!=null){
browserType="欧朋"
    }else if(ua.match(/chrome/)!=null){
browserType="谷歌"
    }else if(ua.match(/safari/)!=null){
browserType="Safari"
    }else{
browserType="edge"
}
$(document).on('focus',':text',function(){
$(this).focus(function(){
this.select()
})
if(browserType!="edge"&&browserType!="IE"){
$(this).mouseup({status:false},function(event){
if(!event.data.status){
event.preventDefault()
event.data.status=event.isDefaultPrevented()
}
})
}
})
})

//

你可能感兴趣的:(jquery)