【问题标题】:Unselectable does not work on webkit不可选择在 webkit 上不起作用
【发布时间】:2013-10-24 13:54:04
【问题描述】:
$('input').on('focus', function() {
    $(this).val('example');
    $(this).attr('unselectable', 'on').css('user-select', 'none').on('startselect', false);
});

当我尝试在 Chrome 或 Opera 上选择字段值时,我能够做到这一点。 在 Firefox 和 IE 上都可以。

有什么方法可以禁用输入字段中的文本选择?

IE 10、Chrome 30、Opera 17。

来源:http://jsfiddle.net/VmDDY/

【问题讨论】:

  • 我相信事件是selectstart,而不是startselect。不知道这是否能解决你的问题。
  • 我认为link 表明您提到的浏览器不支持该功能

标签: jquery input unselect


【解决方案1】:

试试这个,

CSS

.unselectable {
   -moz-user-select: none;
   -webkit-user-select: none;
   -ms-user-select: none;
   user-select: none;
}

脚本

$('input').on('focus', function() {
    $(this).val('example');
    $(this).attr('unselectable', 'on')
           .addClass('unselectable').on('startselect', false);
    //add class ------^
});

Opera不支持user-select

【讨论】:

    【解决方案2】:

    您需要使用所有正确的 CSS 变体:

    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    

    但是这个link 表明你提到的浏览器不支持该功能

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-28
      • 2021-11-04
      • 2014-09-01
      • 2014-02-14
      • 1970-01-01
      • 1970-01-01
      • 2015-10-08
      • 1970-01-01
      相关资源
      最近更新 更多