问题
I have a problem in need of help of JQuery. JQuery give my input to increase the use of case change. the code:
#(".inp").bind("change",function (){
if(isNaN(this.value)){
this.value = 0;
}
}
When I first time to enter characters, change case happened, input values changed to 0 But when I enter the same character a second time, change does not happen.
回答1:
From jQuery documentation:
The change event fires when a control loses the input focus and its value has been modified since gaining focus.
So, it it fired only once. And that's why you have the behaviour you got. I would use the KeyDown event, because
The keydown event fires when a key on the keyboard is pressed.
To use this event you have to do something like this:
$('.inp').keydown(function(event){
switch (event.keyCode) {
// ...
// different keys do different things
// Different browsers provide different codes
// see here for details: http://unixpapa.com/js/key.html
// ...
}
});
回答2:
It looks like you might want to use the keypress event, not the change one.
来源:https://stackoverflow.com/questions/695946/jquery-change-event-trigger