jQuery的更改事件触发器 [英] jquery change event trigger

查看:90
本文介绍了jQuery的更改事件触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要JQuery帮助的问题. jQuery提供了我的输入,以增加大小写更改的使用. 代码:

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;
  }
}

当我第一次输入字符时,发生了大小写更改,输入值更改为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.

推荐答案

来自 jQuery文档:

当控件失去输入焦点并且自获得焦点以来其值已被修改时,将触发change事件.

The change event fires when a control loses the input focus and its value has been modified since gaining focus.

因此,它仅触发了一次.这就是为什么您有自己的行为的原因.我会使用 KeyDown事件,因为

So, it it fired only once. And that's why you have the behaviour you got. I would use the KeyDown event, because

按下键盘上的某个键时会触发keydown事件.

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    
    // ...
  }
});

这篇关于jQuery的更改事件触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆