您的位置:首页 > Web前端 > Vue.js

vue实现页面内容禁止选中,仅输入框和文本域可选

2019-07-04 15:23 751 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/weixin_42873160/article/details/94620342

上网上翻了翻,共找到两种方式

  • CSS样式控制,只需将下面代码复制到 vue应用下,index.html文件中的body标签上
*{
-webkit-touch-callout:none;  /*系统默认菜单被禁用*/
-webkit-user-select:none; /*webkit浏览器*/
-khtml-user-select:none; /*早期浏览器*/
-moz-user-select:none;/*火狐*/
-ms-user-select:none; /*IE10*/
user-select:none;
}
input{
-webkit-user-select:auto; /*webkit浏览器*/
}
textarea{
-webkit-user-select:auto; /*webkit浏览器*/
}
  • js控制方式,需要重写onselectstart(),onselect。(将下面代码复制到body标签上即可,注意此种写法输入框和文本域也不可选)
onselectstart='return false'
onselect='return false'
oncontextmenu='return false' #此句禁用鼠标右键
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐