为什么jQuery的.change()事件仅在鼠标右键单击时触发? [英] Why jQuery's .change() event only fires on right-mouse click?

查看:102
本文介绍了为什么jQuery的.change()事件仅在鼠标右键单击时触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

修改输入元素时,jquery的.change()事件遇到麻烦.据说,每当我对所述元素进行实时更改时,都会触发此事件.但就我而言,它只有在按下右键按钮后才会触发.这是我在laravel框架上的代码:

I am having trouble with jquery's .change() event when I am modifying an input element. Supposedly, this event will fire every time I have live changes on the said element. But in my case it only fires after I have pressed the right-click button. Here are my codes on laravel framework:

HTML:

<div class="form-group">
    <label for="verifyPassword"><h4>Verify Password:</h4></label>
    {{ Form::password('password',array('class'=>'span3 form-control', 'id'=>'verify-password', 'placeholder'=>'Verify Password')) }}
</div>

JS:

$(document).ready(function(){
        $( "#verify-password" ).change(function() {
          alert( "Text Changed!" );
        });
});

希望有人可以帮助我找到麻烦,并为我提供完善的解决方案.谢谢.

Hope someone could help me find the mess and get me with perfect solutions. Thanks.

推荐答案

对于文本字段,在元素失去焦点(并且对其值进行了更改)之前,不会触发change事件.

For text fields, the change event is not fired until the element loses focus (and a change has been made to its' value).

通过API:

对于选择框,复选框和单选按钮,当用户使用鼠标进行选择时,会立即触发该事件,但是对于其他元素类型,该事件将推迟到该元素失去焦点之前.

For select boxes, checkboxes, and radio buttons, the event is fired immediately when the user makes a selection with the mouse, but for the other element types the event is deferred until the element loses focus.

如果需要知道何时立即更改值,请使用keyupkeypress.

If you need to know when the value changes immediately, use keyup or keypress.

这篇关于为什么jQuery的.change()事件仅在鼠标右键单击时触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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