How to modify pasted data ? Jquery

前端 未结 3 1623
囚心锁ツ
囚心锁ツ 2021-01-06 00:02

I followed this question JavaScript get clipboard data on paste event (Cross browser) to get the pasted data from the clipboard, but I used jquery instead. Now that I got t

3条回答
  •  我在风中等你
    2021-01-06 00:30

    Might be easier to let the paste proceed and update element immediately after. Would depend on use case also as cursor position could be lost this way

    $(':input').on('paste', function (e) {
        var $el = $(this); 
        setTimeout(function () {
            $el.val(function(){
                return this.value.replace(/foo/g, "bar"); 
            })
        });
    })
    
    

    foo was here

提交回复
热议问题