简体   繁体   English

document.getElementById('blah')。value的行为不符合预期

[英]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? 是否有任何情况我必须首先将焦点设置在输入文本上( document.getElementById('the_input_text').focus() )才能设置值( document.getElementById('the_input_text').value='123' )为了让我在输入文本中看到值(123)?

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. 不,没有你需要首先关注元素的情况......除非有一些可怕的书面,单独的JavaScript反复硬设置值,直到或除非集中。

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. ...看看是否有JS在设置后覆盖了你的值。

I've tested to ensure that the HTML5 placeholder="..." attribute does not cause a problem with this. 我已经测试过以确保HTML5 placeholder="..."属性不会导致此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM