Javascript document.getElementById(“id”).value returning null instead of empty string when the element is an empty text box

前端 未结 8 1767
清酒与你
清酒与你 2021-01-17 17:09

I have a text box element whose value I am trying to access using document.getElementById(\"id-name\").value. I find that the call is returning a null instead o

8条回答
  •  [愿得一人]
    2021-01-17 17:46

    For your code

    var mytextvalue = document.getElementById("mytext");
    

    mytextvalue will contain null if you have a document.write() statement before this code. So remove the document.write statement and you should get a proper text object in the variable mytextvalue.

    This is caused by document.write changing the document.

提交回复
热议问题