【发布时间】:2021-06-12 00:35:30
【问题描述】:
stackoverflow 上有很多无效的答案,但我正在寻找一个有效的答案:
const textarea = document.getElementsByTagName("textarea")[0];
textarea.style.userSelect = 'none';
textarea.readOnly = true;
textarea.style.cursor = 'default';
textarea.setAttribute("unselectable", "on");
<textarea>
At w3schools.com you will learn how to make a website. They offer free tutorials in all web development technologies.
</textarea>
我想使用纯 javascript(仅)在 chrome 中禁用此 textarea 上的文本选择。
但由于某些原因(可能是错误),这不起作用!
【问题讨论】:
-
此代码有效。您在哪个浏览器中遇到问题?
-
铬............
-
是的,这是在 firefox 上工作的...所以它是 chrome 的大?有什么办法可以解决这个问题?
标签: javascript html css