copy, cut and paste events not working in Opera

2019-03-06 10:04发布

问题:

Why jquery .bind() not working in opera for cut copy paste events?

$(document).ready(function(){
  $('#txtInput').bind("cut copy paste",function(e) {
      e.preventDefault();
  });
});

回答1:

[Update] Opera implemented the Clipboard API in version 12.10 as far as I can tell, although it has been implemented in their Rendering Engine for quite some time (Presto/2.10.292).

This issue is not related to jQuery's bind function but rather to the fact that Opera didn't support cut, copy and paste events before version 12.10.



回答2:

what about alternative?

  $('#txtArea').keydown( function(e){
      if(e.which==17 || e.which == 91) isCtrl=true;
      if(isCtrl) {
        switch(e.which) {
          case 67:  dostuff(); break; //ctrl c
          case 88:  dostuff(); break; //Ctrl x
          case 86:  dostuff(); break; //ctrl 
          default:  break;
        }
        e.preventDefault();
      }
    });