How to track value = ""
change in input
text in real time in jquery? That is, as soon as the value = ""
changed, the alert ($ (this) .val ());
Answer 1, authority 100%
I personally use:
$ (document) .ready (function () {
$ ('selector'). on ('input', function () {alert ('I didn't google the answer: D')})
});
But there are several ways, keyup
, input
, change
events. Choose what suits you best.
Google calls it jQuery event or JavaScript event.
Answer 2, authority 12%
For example:
$ ('input'). on ('keyup', function () {
var $ this = $ (this),
val = $ this.val ();
if (val.length & gt; = 1) {
alert ('the symbol has changed');
}
});
& lt; script src = "https://ajax.googleapis.com/ajax/libs /jquery/1.11.1/jquery.min.js"></script>
& lt; input type = "text" name = "n" id = "n" & gt;