问题
When a user creates a new account on my website I want to check if the name already exists. I want this check to run when they leave the username input box and go to enter a password.
I tried :
<input type="text" onkeyup="check_user(this.value)"/>
回答1:
You need to use the "onblur" event. It fires when a control loses its focus, which seems to be exactly what you need.
回答2:
Call the function on the change
event of text field:
<input name="username" onChange="check_user(this.value);" type="text"/>
回答3:
Because you used onkeyup
in your code example, it sounds like you are looking to call a function on every keystroke. If that is the case, then instead of onchange
- which fires when the input
loses focus - you should use oninput
which will fire anytime there is a change inside of input.
回答4:
I think you are looking for check the duplication of user. you have to write server side code for that.
来源:https://stackoverflow.com/questions/4886114/how-can-i-run-a-javascript-function-when-input-changes