当我修改输入元素时,我遇到了 jquery 的 .change()
事件的问题。据说,每当我对所述元素进行实时更改时,该事件就会触发。但就我而言,它仅在我按下右键单击按钮后才会触发。这是我在 laravel
框架上的代码:
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!" );
});
});
希望有人能帮助我找到困惑的地方并为我提供完美的解决方案。谢谢。
最佳答案
对于文本字段,直到元素失去焦点(并且对其值进行了更改)后才会触发 change
事件。
来自 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.
如果您需要知道值何时立即更改,请使用 keyup
或 keypress
。
关于javascript - 为什么 jQuery 的 .change() 事件仅在单击鼠标右键时触发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24055587/