Differences between keyup() event and change() event in username live change

后端 未结 2 877
  • username html field

    Username: 
    
  • keyup() event

    
    
            
2条回答
  •  孤城傲影
    2020-12-17 15:47

    They are almost the same thing. In jQuery or JavaScript, I would have to recommend the change() event. The reason you should not use keyup() is because if a user inputs a value using autofill, it will not fire the keyup() event. However, autofill does fire the change() event, and your verification script will run, and the input will be verified.

    NOTE: Normally, change() is fired when the element loses focus. If you want to check data after every key press, you could combine keyup() and change(), which would allow you to parse the data on both events. This is the best of both worlds in my opinion.

    Hope this helps!

提交回复
热议问题