Chrome下input输入框内容无法选中的解决方法

 

$("input").click(function(e){
  $(this).select();
});

上述方法在firefox和IE下都正常(注意,不要用focus方法,有时也不正常),唯独在chrome中有时成功有时失败。解决方法如下:

阻止chrome自己的mouseup事件即可。

$("input").mouseup(function(e){
    if(window.navigator.userAgent.indexOf("Chrome")!=-1){
        var event = e||window.event; 
        event.preventDefault(); 
    }
});

 

 

posted on 2012-08-07 13:41  萌二&威比  阅读(1408)  评论(0编辑  收藏  举报

导航