问题
if i use this style for the <body>
onmousedown='return false;' onselectstart='return false;'
is it possible to give the exceptions by using javascript for inputs textareas and selects? and if yes then can u show me how?
回答1:
Actually, you can disable text selection without needing heavy-handed JavaScript event handlers. See my answer here: How to disable text selection highlighting using CSS?
Summary: use CSS and the unselectable
expando in IE.
CSS:
*.unselectable {
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
-o-user-select: none;
user-select: none;
}
HTML:
<div id="foo" unselectable="on" class="unselectable">...</div>
回答2:
You need to prevent event bubbling for textboxes and selects.
You can use :input selector to select all input, textarea, select and button elements.
Something like
$(":input").bind("mousedown", function(e){
e.stopPropagation();
});
See a working demo
来源:https://stackoverflow.com/questions/4712030/disable-text-selection-and-add-exceptions