Home>

First of all, change event is recognized to fire when the control goes out of focus.
is it right?
https://qiita.com/maruyam-a/items/cf0168f91d934b449a07

However, when the following code is executed, a change event alert is displayed every time
The change event does not fire even when the focus is removed from the control.
Please teach me.

Applicable source code
<input></input>
$('# input1'). on ({
        "keypress": function (e) {
                        // When the Enter key is pressed.
                        if (e.which == 13) {
                            alert ("Enter key pressed");
                        }
                    },
        "input": function (e) {
                    alert ("Fires on every input:" + $('# input1'). val ());
                },
        "change": function (e) {
                    alert ("Out of focus");
                }
    });
Added. I changed the output to

console.log, but the behavior is not yet intended.

-If i press the Enter key after entering a character, a log indicating that the focus has been lost appears.
If i press the Enter key in succession, there will no longer be a log that the focus has been lost.
-If i do not remove the focus after entering characters, there will be no log that the focus has been lost.
Even if you change the focus many times without entering characters (go back and forth with other controls)
There is no log that the focus is lost.

Supplemental information (FW/tool version etc.)

Google Chrome

  • Answer # 1

    Recognition is correct, but in the case of this code, it will be fired at each input because it will focus out each time alert is issued with input.

  • Answer # 2

    Alert takes control, so please see console.log in the development environment

Related articles