简体   繁体   中英

document.getElementById('blah').value not behaving as expected

Is there any situation where I would have to set the focus on a input text first ( document.getElementById('the_input_text').focus() ) before I could set the value ( document.getElementById('the_input_text').value='123' ) in order for me to see the value (123) in the input text?

I'm only asking because I have to do that on this page that I'm working on in order for me to see the value in the input text.

No, there is no case where you need to focus the element first…unless there is some horribly-written, separate JavaScript repeatedly hard-setting the value until or unless focused.

You might try:

setTimeout(function(){
  document.getElementById('the_input_text').value='123'
},2000);

…to see if there is JS that was overriding your values after setting them.

I've tested to ensure that the HTML5 placeholder="..." attribute does not cause a problem with this.

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