使用JQuery捕获粘贴到textarea中的文本

Jib*_*oor 12 jquery copy-paste javascript-events

我必须使用JQuery来获取文本区域的粘贴事件.我尝试了以下代码,但它不起作用......

$(document).ready(function()
{ 
  $('#txtcomplaint').keyup(function()
  {  
     TextCounter('txtcomplaint','counterComplaint', 1000 ); 
  }) 
  $('#txtcomplaint').onpaste(function()
  {  
     alert()
     //TextCounter('txtcomplaint','counterComplaint', 1000 ); 
  }) 
});
Run Code Online (Sandbox Code Playgroud)

rah*_*hul 25

你可以做这样的事情

$("#txtcomplaint").bind('paste', function(e) {
    var elem = $(this);

    setTimeout(function() {
        // gets the copied text after a specified time (100 milliseconds)
        var text = elem.val(); 
    }, 100);
});
Run Code Online (Sandbox Code Playgroud)


Fit*_*aki 6

$('#txtcomplaint').bind('paste', function(e){ alert('pasting!') });
Run Code Online (Sandbox Code Playgroud)

有关其他资源,请查看此处.