【问题标题】:Disable Text Selection in IE禁用 IE 中的文本选择
【发布时间】:2013-10-14 13:28:59
【问题描述】:

我正在尝试禁用文本选择,它在除 IE 之外的所有浏览器中都能正常工作。我在 CSS 和索引中添加了一些代码。它仍然没有禁用。

我已将此添加到索引中:

$('#poet').disableSelection(); // deprecated in jQuery UI 1.9

$(el).attr('unselectable','on')
.css({'-moz-user-select':'-moz-none',
       '-moz-user-select':'none',
       '-o-user-select':'none',
       '-khtml-user-select':'none', /* you could also put this in a class */
       '-webkit-user-select':'none',/* and add the CSS class here instead */
       '-ms-user-select':'none',
       'user-select':'none'
 }).bind('selectstart', function(){ return false; });

 $("#123").bind( "selectstart", function(e){
    e.preventDefault();
    return false;
});

 $("#123").bind("selectstart", function (evt) {
    evt.preventDefault();
});

还有这个 .css 文件:

* {
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none; 
-ms-user-select:none;
}

任何帮助将不胜感激。谢谢。

【问题讨论】:

    标签: jquery internet-explorer internet-explorer-8 textselection


    【解决方案1】:

    将这两个添加到您现有的 CSS 类中

    -webkit-touch-callout: none;
    user-select: none;
    

    此外,您可以查看此链接了解更多详情。

    http://msdn.microsoft.com/en-us/library/ie/jj152140(v=vs.85).aspx


    Prevent text selection when dragging from outside target in IE7/8


    鉴于这篇文章指定了“jquery”:

    $("#inputID").focus(function() {
        $(this).blur();
    }):
    

    【讨论】:

    • 新的-webkit 将如何帮助它与IE 一起工作?
    • @Cristy 通过查看他的代码示例,很明显他正在尝试禁用所有浏览器(包括 IE)的选择。这是他班上仅有的两个完成这项任务的人。
    • 非常感谢@adam 的帮助,但由于某种原因它仍然无法正常工作。我的代码现在包含: /**STOP_HIGHLIGHTING**/ * { -webkit-touch-callout: none; -webkit 用户选择:无; -khtml-用户选择:无; -moz 用户选择:无; -ms 用户选择:无;用户选择:无; }
    • 并且 javascript 包含: $(el).attr('unselectable','on') .css({'-moz-user-select':'-moz-none', '- moz-user-select':'none', '-o-user-select':'none', '-khtml-user-select':'none', '-webkit-user-select':'none', '-ms-user-select':'none', 'user-select':'none' }).bind('selectstart', function(){ return false; }); $("#123").bind("selectstart", function (evt) { evt.preventDefault(); }); $("#inputID").focus(function() { $(this).blur(); }):
    • @adam 我更擅长 HTML 和 CSS,至于 jQuery,我只是复制和粘贴我找到的代码,并且在代码学院上过一些课程。你能解释一下 jQuery blur 是什么意思吗?我最后确实有这个: $("#inputID").focus(function() { $(this).blur(); }):
    猜你喜欢
    • 2012-09-09
    • 1970-01-01
    • 1970-01-01
    • 2011-09-07
    • 1970-01-01
    • 2023-04-02
    • 2010-12-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多