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

本文操作环境: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中文网其它相关文章!
HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号