简体   繁体   中英

Update "value"= attribute of <input> on changing the value in UI or When enter Pressed

I have an input field of text type in my HTML file. It Doesn't belong to any form . So i was actually trying to give input there and later take care of the input (In my case, make a POST request with ajax) by let's say collecting .value from these input field by referring it with document.getElementById() .But apparently the value i enter or edit on the UI there is not being "saved" in value attribute. As a result i am not being able to fetch those values later from js. So is there any way for "saving" ui edited values in value attribute?

You don't provide any code, but this snippet worked for me.

 function clicked(){ var el = document.getElementById('input'); console.log(el.value); }
 <input type="text" id="input"/> <button onclick="clicked()">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