Catch paste input

后端 未结 17 2090
名媛妹妹
名媛妹妹 2020-11-22 08:09

I\'m looking for a way to sanitize input that I paste into the browser, is this possible to do with jQuery?

I\'ve managed to come up with this so far:



        
17条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 08:24

    See this example: http://www.p2e.dk/diverse/detectPaste.htm

    It essentialy tracks every change with oninput event and then checks if it’s a paste by string comparison. Oh, and in IE there’s an onpaste event. So:

    $ (something).bind ("input paste", function (e) {
        // check for paste as in example above and
        // do something
    })
    

提交回复
热议问题