开发者

Non-selectable columns in HTML table

I have a table with multiple columns. I want content of each column to be selected individually. When I start selecting first column, second, third ... are automatically getting selected. When I select one column I want make other columns non selectable.

I have tried applying following class on elements and it worked fine i开发者_开发知识库n Firefox. No matter where you start selection from, its never selectable.

.unselectable {
    user-select: none; /* CSS3 */
    -moz-user-select: none;
    -khtml-user-select: none;
}

For IE I have tried property called unselectable="on", In Internet Explorer, it is still selectable if the selection starts outside. I want to prevent selection of certain columns even selection starts from outside.

I have tried using onselectionstart and onmouseover but as the selection is starting outside of element these are not getting triggered.

Do I have any hope ?


I believe that for now there is no pure CSS solution.

It may sound weird, but you could clone the content of the column you want the user to select into a separate table that will be positioned: absolutely over the original column.


Instead of reinventing the wheel... check out http://www.datatables.net/

This is a JQuery table plug-in that'll knock your socks off.

It looks like it is already doing what you would like to do and it is free.


It might help to include a TH with a SCOPE attribute. Can't say it will work, but it does make for a more semantic table. CSS can hook the attribute, so a DOM solution can't be that far off.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜