jQuery bind to Paste Event, how to get the content of the paste

后端 未结 9 1073
温柔的废话
温柔的废话 2020-11-28 06:08

I have a jquery token tagit plugin and I want to bind to the paste event to add items correctly.

I\'m able to bind to the paste event like so:

    .b         


        
9条回答
  •  星月不相逢
    2020-11-28 06:56

    There is an onpaste event that works in modern day browsers. You can access the pasted data using the getData function on the clipboardData object.

    $("#textareaid").bind("paste", function(e){
        // access the clipboard using the api
        var pastedData = e.originalEvent.clipboardData.getData('text');
        alert(pastedData);
    } );
    

    Note that bind and unbind are deprecated as of jQuery 3. The preferred call is to on.

    All modern day browsers support the Clipboard API.

    See also: In Jquery How to handle paste?

提交回复
热议问题