首页  >  文章  >  web前端  >  怎么实现html禁止选择

怎么实现html禁止选择

藏色散人
藏色散人原创
2021-04-12 09:36:262858浏览

html禁止选择的实现方法:1、通过css的方式实现禁止html内容被选中;2、通过在body标签中添加onselectstart等属性实现禁止html内容被选中;3、通过在js中添加onselectstart语句实现禁止。

怎么实现html禁止选择

本文操作环境:windows7系统、HTML5&&CSS3版、Dell G3电脑。

页面中,禁止html内容被选中

1、通过css的方式

*{
moz-user-select: -moz-none;
-moz-user-select: none;
-o-user-select:none;
-khtml-user-select:none;
-webkit-user-select:none;
-ms-user-select:none;
user-select:none;
}

user-select属性:参考https://www.html.cn/book/css/properties/user-interface/user-select.htm

2、通过在body标签中添加如下属性:

<body "return false;" onselectstart="return false">

前面一句是禁止右键的,后面一句是禁止复制的。

3、在js中添加如下两行语句:

//禁止页面选择以及鼠标右键
document.function(){return false;}; 
document.onselectstart=function(){return false;};

【推荐学习:HTML视频教程

以上是怎么实现html禁止选择的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn