admin管理员组

文章数量:1355520

Here, I'm having a problem with copy option when select 3 elements all the three are getting copied. But, I have a Jquery function to disable copy for the middle element. How I can disable that while selecting 3 elements. But, If I select the middle element individually it's not copying.

$('#notcp').bind('cut copy paste', function (e) {
    e.preventDefault();
});
<script src=".1.1/jquery.min.js"></script>
<p >
select and copy
</p>
<p id="notcp">
cannot copy
</p>
<p>
select and copy
</p>

Here, I'm having a problem with copy option when select 3 elements all the three are getting copied. But, I have a Jquery function to disable copy for the middle element. How I can disable that while selecting 3 elements. But, If I select the middle element individually it's not copying.

$('#notcp').bind('cut copy paste', function (e) {
    e.preventDefault();
});
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p >
select and copy
</p>
<p id="notcp">
cannot copy
</p>
<p>
select and copy
</p>

Share Improve this question asked May 26, 2017 at 11:53 Satya PendemSatya Pendem 3255 silver badges14 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 3

Use This CSS Style to disable Selection. By this The Text will not be selected. Thus can't be copied also.

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

This feature can be done via disabling Text Selection using few CSS lines:

html, body {
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -o-user-select: none;
  user-select: none;
}

try add return false;

   $('#notcp').bind('copy paste',function(e) {
    e.preventDefault(); return false; 
});

Try with this.

$(document).on("cut copy paste","#notcp",function(e) {
    e.preventDefault();
});

本文标签: javascripthow to disable copy for particular element in htmlStack Overflow