Javascript allow only numeric paste

后端 未结 3 1795
梦谈多话
梦谈多话 2021-01-07 11:35

Javascript/jQuery:

 $(document).ready(function () {
     $(\'#txt\').bind(\"paste\", function (e) {
         var $this = $(this);
         $         


        
3条回答
  •  情歌与酒
    2021-01-07 12:23

    The jquery event should be:

    $('#.txt').on('paste', function() {...});
    

    See example here: Catch paste input

    Note the use of a timeout to allow the value to be pasted before you manipulate it.

    Once you properly handle the event and get the pasted value, you can add your validation.

    Also see ste-fu's answer about referencing the proper field, as asp.net will by default append the container's is to your text box id and the selector '#txt' won't work.

提交回复
热议问题