How do I capture the input value on a paste event?

后端 未结 5 1072
清歌不尽
清歌不尽 2020-12-05 10:08

On my site users can paste text (in this case a url) into an input field. I\'d like to capture the value of the text that was pasted using jQuery. I\'ve got this to work in

5条回答
  •  情歌与酒
    2020-12-05 11:04

    jQuery has a problem with the live-method with the paste-event in the IE; workaround:

    $(document).ready(function() {
        $(".url").bind('paste', function(event) {
            var _this = this;
            // Short pause to wait for paste to complete
            setTimeout( function() {
                var text = $(_this).val();
                $(".display").html(text);
            }, 100);
        });
    });
    

    Fiddle: http://jsfiddle.net/Trg9F/

提交回复
热议问题