html - css 技巧在复制粘贴时禁用文本选择

标签 html css

我有一个字母序列,每个字母上面都有数字。我想禁用文本选择,这样当用户从屏幕上复制粘贴字母序列时,他不会得到数字。

我实际上没有使用 select css 技巧,数字被排除在选择之外,但我得到了数字所在的空格。像这样:

T

QD

所需的输出是:

TQD

这是我的代码:

<div style="margin-bottom:0px;font-size: 0.65vw;">
  <div style="display:inline-block;width:1.3vw;font-size: 0.8vw; text-align: center">
  <p style="-moz-user-select: none;-ms-user-select: none;-webkit-user-select: none; -webkit-touch-callout: none;background-color:#ededed;margin: 0px;font-size:0.6vw;padding-top: 2px; height:0.6vw;">1</p>
  <span style="background-color:hsl(60,100%,60%);width:1.3vw;font-size: 0.8vw;display:inline-block;text-align: center;padding-top:2px">T</span></div>
  <div style="display:inline-block;width:1.3vw;font-size: 0.8vw; text-align: center">
<p style="-moz-user-select: none;-ms-user-select: none;-webkit-user-select: none; -webkit-touch-callout: none;background-color:#ededed;margin: 0px;font-size:0.6vw;padding-top: 2px; height:0.6vw;">2</p>
<span style="background-color:hsl(60,100%,60%);width:1.3vw;font-size: 0.8vw;display:inline-block;text-align: center;padding-top:2px">Q</span></div>
  <div style="display:inline-block;width:1.3vw;font-size: 0.8vw; text-align: center">
<p style="-moz-user-select: none;-ms-user-select: none;-webkit-user-select: none; -webkit-touch-callout: none;background-color:#ededed;margin: 0px;font-size: 0.6px;padding-top: 2px;height:0.6vw;"></p>
<span style="background-color:hsl(60,100%,60%);width:1.3vw;font-size: 0.8vw;display:inline-block;text-align: center;padding-top:2px">D</span></div></div>

有什么 css 技巧吗?

最佳答案

如果您可以禁用 ctrl 按钮并右键单击网页,则复制粘贴功能将自动禁用。我认为以下代码会对您有所帮助。

<script>
  $(window).on('keydown',function(event)
 {
 if(event.keyCode==123)
 {
    alert(' Developer Tools is disable from this website.');
    return false;
 }
 else if(event.keyCode==17)
 {
    alert('Control key is disable from this website.');
    return false;
 }    

  });
  $(document).on("contextmenu",function(e)
 {
   alert('Right click is disable from this website!')
  e.preventDefault();
 });

 </script>

关于html - css 技巧在复制粘贴时禁用文本选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57431198/

相关文章:

javascript - 打印 div 有效,但在 jQuery 顶部有空格

html - 如何让这些 id 标签的样式正确?

javascript - 什么时候应该使用 CSS 与 Javascript 控制背景图像的变化?

html - 类输入组在 Firefox 和 IE 中不显示占位符或接受输入

javascript - 使新元素在特定时间出现

javascript - 如何禁用 div 以停止关闭

javascript - 单选按钮隐藏和显示表单内容

html - 我可以将高度方向从自上而下反转为自下而上吗?

javascript - 将我的页面更新为 jQuery

javascript - 寻找实时跨浏览器移动应用程序的框架