文本在IE中无法选择 [英] Text unselectable in IE

查看:93
本文介绍了文本在IE中无法选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要我的网页上有一个HTML元素(标签)无法选择IE ...目前我已尝试过


  1. Unselectable = on

  2. onselectreturn = false;



  3. 对于Firefox和Chrome,我设置了以下CSS属性:正在工作绝对正常...但问题一如既往的IE。



    您设置的CSS属性:

      -moz-user-select:-moz-none; 
    -khtml-user-select:none;
    -webkit-user-select:none;
    -o-user-select:none;
    user-select:none;

    是否有任何替代方案或IE-hack?



    有关 Stack Overflow的回答

    在IE8中,有两种方法使元素无法选择:



    1。) myElement.unselectable =on; //不适用于body元素



    2) myElement.onselectstart = function(){return false; }



    一旦元素无法选择,用户就无法从该元素中选择。
    然而,他们仍然能够通过从另一个不可选择的元素中拖动元素
    来选择元素的文本或框。



    我试图解决这个问题,通过取消myElement(ondragenter,oncontrolselect,onmouseenter,onselectionchange ...)上的各种事件,它不工作。



    所有这些仅适用于IE8


    I require one HTML element (Label) on my page to be unselectable for IE ... currently I have tried

    1. Unselectable=on
    2. onselectreturn=false;

    none of which is helping me out.

    For Firefox and Chrome i have set the following CSS property which are working absolutely fine ... but the problem as always with the IE.

    CSS properties you have set:

    -moz-user-select: -moz-none;
    -khtml-user-select: none;
    -webkit-user-select: none;
    -o-user-select: none;
    user-select: none;
    

    is there any alternative or IE-hack?

    An answer on Stack Overflow has helped me out but not for IE.

    解决方案

    In IE8 there are two ways to make an element unselectable:

    1.) myElement.unselectable = "on"; // Does not work on body elements

    2.) myElement.onselectstart = function (){ return false; }

    Once an element is unselectable, users cannot select from within that element. However, they are still able to select either the text or the box of the element by dragging into it from within another element which is not unselectable.

    I have tried to work around this by cancelling various events on myElement (ondragenter, oncontrolselect, onmouseenter, onselectionchange...), it didn't work.

    All this applies only to IE8

    这篇关于文本在IE中无法选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆