开发者

Switchable selectable text

开发者 https://www.devze.com 2023-03-08 02:57 出处:网络
I have a table which is filled with data from a database. Some javascript allows a user to select certain rows and take some actions. I allow users to click one row and then to shift click another row

I have a table which is filled with data from a database. Some javascript allows a user to select certain rows and take some actions. I allow users to click one row and then to shift click another row to create a group (as well as alt-click to select/desel开发者_开发技巧ect individual rows).

The problem is I don't like how the text highlights when they shift click. Is there some CSS setting or javascript/jQuery solution to disable the selectable text (cross browser preferablly or just in firefox).

If possible I also want to be able to let the user select text to copy and paste sometimes or inside a textbox form input inside the same table so I would like to be able to enable and disable the selecting of text somehow. Any ideas?


this should do the trick:

$('td').disableSelection();

example: http://jsfiddle.net/GhfuJ/1/


Here's one way you could completely disable text selection:

$("selector").bind($.support.selectstart ? "selectstart" : "mousedown", function(event) {
    event.preventDefault();
});

This is how jQueryUI implements its disableSelection() method.

You could tailor your selector to exclude textarea elements, or wrap code inside the event handler with an if block that evaluates a boolean that gets set under certain circumstances (For example, you could turn on booleans when the user is clicking or shift/alt + clicking).

0

精彩评论

暂无评论...
验证码 换一张
取 消