Making text unselectable [duplicate]

别说谁变了你拦得住时间么 提交于 2019-12-01 14:46:52

问题


So, while playing with scrollbars and stuff in HTML5, I'm starting to notice an annoying trend. If I have text near my element that's being dragged (say, a scrub bar for a video, scroll bar, anything a user would click and drag), nearby text will get selected, as if I'm not using a control, just dragging over the page.

This is terribly annoying, and I can't seem to find the right string to search for on google to figure out if it's possible to make certain elements "unselectable".

Anyone know how to do this?


回答1:


It varies per browser. These CSS properties will target WebKit and Gecko-based browsers, as well as any future browsers that support user-select:

user-select: none;
-webkit-user-select: none;
-moz-user-select: none;



回答2:


In IE you can make text immediately within an element unselectable (i.e. doesn't apply to text in its children) by using the unselectable="on" attribute.

Note that if applying from javascript you MUST use el.setAttribute("unselectable","on"). Just trying el.unselectable="on" will not work. (Tested in IE9).



来源:https://stackoverflow.com/questions/5207723/making-text-unselectable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!