[英]How to make editable textarea text non-selectable
I'm trying to create a textarea that is not read-only (users can type), but they cannot select and drag. 我正在尝试创建一个非只读的textarea(用户可以键入),但他们无法选择和拖动。
All that I found either turns the textarea into readonly, or disables my ability to focus. 我发现的所有东西要么将textarea变成只读,要么禁用我的聚焦能力。
Appreciate any help. 感谢任何帮助。
In jQuery 1.8, this can be done as follows: 在jQuery 1.8中,可以按如下方式完成:
$('textarea')
.attr('unselectable', 'on')
.css('-webkit-user-select', 'none')
.css('-moz-user-select', 'none')
.css("-ms-user-select","none")
.css("-o-user-select","none")
.css("user-select",'none')
.on('selectstart', false)
.on('mousedown', false);
or by just using css, 或者只使用css,
#yourtextarea
{
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
}
You can use the CSS style user-select: none;
您可以使用CSS样式user-select: none;
to keep text from being selectable. 保持文本不被选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.