不可粘贴代码。这个的用途在给学生在网上做题时用的
<div mce-contenteditable="false" id="noPasteBox" style="border: 1px solid #ccc; padding: 10px;">
<textarea name="text" id="" cols="30" rows="10"></textarea>
</div>
<script>
// 获取要禁止粘贴的文本框元素
var noPasteBox = document.getElementById('noPasteBox');
// 添加粘贴事件监听器
noPasteBox.addEventListener('paste', function (e) {
e.preventDefault(); // 阻止粘贴操作
alert('不允许粘贴内容!');
});
</script>
不可复制的代码,改ID值就能换不可复制的内容
<input type="text" id="noCopyInpu" value="这个文本框不可复制" readonly oncontextmenu="return false;">
<h1 id="noCopyInput">山海云端欢迎您</h1>
<script>
// 禁止复制文本框中的内容
var noCopyInput = document.getElementById('noCopyInput');
noCopyInput.addEventListener('copy', function (e) {
e.preventDefault();
alert('该内容不可复制!');
});
</script>
或者把他们放到一个区块里,然后再js里再引用区块id
<div id="ishere">
<input type="text" id="noCopyInpu" value="这个文本框不可复制" readonly oncontextmenu="return false;">
<h1 id="noCopyInput">山海云端欢迎您</h1>
</div>
<script>
// 禁止复制文本框中的内容
var noCopyInput = document.getElementById('ishere');
noCopyInput.addEventListener('copy', function (e) {
e.preventDefault();
alert('该内容不可复制!');
});
</script>
© 版权声明
THE END
暂无评论内容