Catch paste input

后端 未结 17 2097
名媛妹妹
名媛妹妹 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:45

    There is one caveat here. In Firefox, if you reset the input text on every keyup, if the text is longer than the viewable area allowed by the input width, then resetting the value on every keyup breaks the browser functionality that auto scrolls the text to the caret position at the end of the text. Instead the text scrolls back to the beginning leaving the caret out of view.

    function scroll(elementToBeScrolled) 
    {
         //this will reset the scroll to the bottom of the viewable area. 
         elementToBeScrolled.topscroll = elementToBeScrolled.scrollheight;
    }
    

提交回复
热议问题