使IE在IE中无法选择 [英] Making things unselectable in IE

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

问题描述

这是我一直在JS写的图表:

Here is my chart I've been writing in JS:

http:/ /jsfiddle.net/49FVb/

css:

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

适用于Chrome / FF,但在IE中所有的元素仍然可以选择,看起来很奇怪,拖动

Works fine for Chrome/FF, but in IE all the elements are still selectable which looks weird when dragging the bars around.

如何在IE中取消选择?

How can I make this unselectable in IE?

推荐答案

在IE中,您需要HTML中的 unselectable 属性: / p>

In IE, you need the unselectable attribute in HTML:

<div id="foo" unselectable="on">...</div>

...或通过JavaScript设置:

... or set it via JavaScript:

document.getElementById("foo").setAttribute("unselectable", "on");

要注意的事情是,不可选择性不是由不可选元素的子元素继承的。这意味着你必须在< div> 中的每个元素的开始标签中使用属性,或者使用JavaScript对元素的后代递归地执行:

The thing to be aware of is that the unselectableness is not inherited by children of an unselectable element. This means you either have to put an attribute in the start tag of every element inside the <div> or use JavaScript to do this recursively for an element's descendants:

function makeUnselectable(node) {
    if (node.nodeType == 1) {
        node.setAttribute("unselectable", "on");
    }
    var child = node.firstChild;
    while (child) {
        makeUnselectable(child);
        child = child.nextSibling;
    }
}

makeUnselectable(document.getElementById("foo"));

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

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