简体   繁体   中英

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");

最好使用keypress代替change

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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