Strip white spaces on input

前端 未结 4 657
一个人的身影
一个人的身影 2020-12-02 14:56

I have a field that does not need any white spaces. I need to remove any as they are entered. Here\'s what I\'m trying... no luck so far

$(\'#noSpacesField\'         


        
4条回答
  •  日久生厌
    2020-12-02 15:38

    If you only wanna put numbers, try this! :D

    $("#id").keyUp(function(){
       if(isNaN($(this).val())) {
         $(this).val(0);
       }
       $(this).val($(this).val().replace(/ +?/g, ''));
    })
    

提交回复
热议问题