Jquery “不可选择”在webkit上不起作用

Jquery “不可选择”在webkit上不起作用,jquery,input,unselect,Jquery,Input,Unselect,当我尝试在Chrome或Opera上选择字段值时,我能够做到这一点。 在Firefox和IE上也可以 有没有办法禁用输入字段中的文本选择 IE 10、Chrome 30、Opera 17 来源:试试这个 CSS $('input').on('focus', function() { $(this).val('example'); $(this).attr('unselectable', 'on').css('user-select', 'none').on('startselec

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

有没有办法禁用输入字段中的文本选择

IE 10、Chrome 30、Opera 17

来源:

试试这个

CSS

$('input').on('focus', function() {
    $(this).val('example');
    $(this).attr('unselectable', 'on').css('user-select', 'none').on('startselect', false);
});
脚本

.unselectable {
   -moz-user-select: none;
   -webkit-user-select: none;
   -ms-user-select: none;
   user-select: none;
}
Opera不支持

试试这个

CSS

$('input').on('focus', function() {
    $(this).val('example');
    $(this).attr('unselectable', 'on').css('user-select', 'none').on('startselect', false);
});
脚本

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

Opera不支持

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

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

但这表明您提到的浏览器不支持该功能

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

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

但这表明您提到的浏览器不支持该功能

我相信事件是
selectstart
,而不是
startselect
。但不确定这是否能解决您的问题。我想这说明您提到的浏览器不支持该功能。我认为事件是
selectstart
,而不是
startselect
。不确定这是否能解决您的问题。我想这说明您提到的浏览器不支持该功能