Why jQuery's .change() event only fires on right-mouse click?

僤鯓⒐⒋嵵緔 提交于 2019-12-11 00:31:26

问题


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.


回答1:


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

From the 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.

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



来源:https://stackoverflow.com/questions/24055587/why-jquerys-change-event-only-fires-on-right-mouse-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!