Strip white spaces on input

前端 未结 4 654
一个人的身影
一个人的身影 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:47

    We can achieve the desired outcome with pure javascript.

    Input

    removeSpace(e) } />
    

    Js Function

    function removeSpace(e){
        let val = (e.target.value).trim();
        console.log(val);
    }
    

    However on a form submit button clicked

    console.log( ( (" test case ").trim() ).replace(" ", "") )
    

提交回复
热议问题