在div及其所有子元素上禁用文本选择的语法是什么?我使用$("#MyContent).disableSelection()禁用下面代码中的所有文本,它在firefox中有效,并且一次禁用所有三行。
在IE Explorer9中,它不适用于子元素,所以为了禁用所有的文本,我必须做$("#text1).disableSelection(),$("#text2).disableSelection(),$("#text3).disableSelection()。
<div id="MyContent">
  <div id="text1">Hello World</div>
  <div id="text2">Goodbye</div>
  <div id="text3">Asdf</div>
</div>发布于 2012-03-19 12:03:50
这对我来说很有效:
$('#MyContent').children().each(function(i, c) {
    disableSelection(c);
});
function disableSelection(target) {
    console.debug(target);
    if (typeof target.onselectstart != "undefined")             // For IE
        target.onselectstart = function() { return false };
    else if (typeof target.style.MozUserSelect != "undefined")  // For Firefox
        target.style.MozUserSelect = "none";
    else                                                        // All other routes (Opera, etc.).
        target.onmousedown = function() { return false };
    target.style.cursor = "default";
}演示:http://jsfiddle.net/9vLFD/4/
发布于 2012-03-19 11:29:45
你可以试一试
$('#MyContent').children().each(function(i,c){
    $(c).disableSelection();
});https://stackoverflow.com/questions/9764635
复制相似问题