简体   繁体   English

为什么浏览器不触发更改事件

[英]Why browser doesn't fire change event

I have 我有

<input type="text" id="pies" value="" />

and

$( document ).ready(function() {
    $('#pies').on('change', function() { alert('cham'); });
    $('#pies').focus();
    $('#pies').val('kooooo');
    $('#pies').blur();
});

Why browser doesn't fire change event? 为什么浏览器不触发更改事件? How can I make that browser will fire change event. 如何使该浏览器触发更改事件。 I don't want to trigger "change" manually, because if I will trigger change, in some cases trigger change will be triggered twice. 我不想手动触发“更改”,因为如果我将触发更改,则在某些情况下,触发更改将被触发两次。 This is only example. 这仅是示例。

使用以下命令致电更改:

$('#pies').change();

You have to do it manually 你必须手动做

$('#pies').change();

As docs says 正如文档所说

The change event is sent to an element when its value changes. 更改事件在其值更改时发送到元素。 This event is limited to elements, boxes and elements. 此事件仅限于元素,框和元素。 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. 对于选择框,复选框和单选按钮,当用户使用鼠标进行选择时会立即触发该事件,但是对于其他元素类型,该事件将推迟到该元素失去焦点之前。

In auto complete case try to do $("#pies").trigger("autocompleteselect"); 在自动完成的情况下,尝试执行$("#pies").trigger("autocompleteselect");

最好使用keypress代替change

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM