2010-07-27 7 views

Répondre

1

J'ai écrit méthodes Prototype.js pour cela, vous pouvez les utiliser.

Element.addMethods({ 
    /** 
    * Makes element unselectable. Disables cursor select 
    * @param {Object} target 
    */ 
    setUnselectable: function(target){ 
     if (typeof target.onselectstart != "undefined") {target.onselectstart = function(){return false;};} 
     else if (typeof target.style.MozUserSelect != "undefined") { target.style.MozUserSelect = "none";} 
     else {target.onmousedown = function(){ return false;}; } 
     return target; 
    }, 
    /** 
    * Reverts unselectable effect, Enables cursor select 
    * @param {Object} target 
    */ 
    setSelectable: function(target){ 
     if (typeof target.onselectstart != "undefined") { target.onselectstart = document.createElement("div").onselectstart; } 
     else if (typeof target.style.MozUserSelect != "undefined") { target.style.MozUserSelect = document.createElement("div").style.MozUserSelect; } 
     else { target.onmousedown = ""; } 
     return target; 
    } 
}); 

Pour faire un élément unselectable

$('element_id').setUnselectable(); 

Pour rétablir en arrière

$('element_id').setSelectable(); 
0

Pour couvrir toutes les bases, fixées toutes ces propriétés dans votre css:

user-select: none 
-webkit-user-select: none 
-khtml-user-select: none 
-moz-user-select: none 
Questions connexes