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(); 
    }
});

 

原文地址:https://www.cnblogs.com/danye/p/2626572.html