简体   繁体   中英

Get info from textbox without submit button in JavaScript?

How can I do this? I basically want to call a function where I get the info from the textbox once the user is done entering info. Ie, after they click off of the text box. I couldn't find the clear way to do this. Is there an API for event/actions and what you can do on each input?

Try the blur event:

yourTextBox.onblur = function() {
    console.log(yourTextBox.value);
};

or

yourTextBox.addEventListener('blur', function() {
    console.log(yourTextBox.value);
});

See the documentation for the blur event on MDN here .

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