简体   繁体   中英

How do I wait for input to be filled in an html page and then print it's value to the console in javascript?

I have a HTML page with an input field
Someone enters some text into it
They click a button

I want to grab the value of the input field AFTER they click the button with some JS code(client-side) and then print it to the console/save it to a file.

How would I go about doing this? I've tried looking but I can't find anything like this at all :/

Thanks! :)

This example should help you to achieve your goals.

 const inputNode = document.getElementById('input'); const buttonNode = document.getElementById('button'); buttonNode.addEventListener('click', () => { const inputValue = inputNode.value; // do what ever you wan't }); 
 <input id="input" type="text" /> <button id="button">Click</button> 

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