document.getElementById().value return undefined in chrome

后端 未结 3 1821
攒了一身酷
攒了一身酷 2020-12-14 11:11
2

JavaScript code:



        
相关标签:
3条回答
  • 2020-12-14 11:34
    document.getElementById("hour").innerText
    

    or

    document.getElementById("hour").innerHTML
    
    0 讨论(0)
  • 2020-12-14 11:46

    divs do not have a value. It is not an input.

    You want to use innerHTML or innerText/textContent.

    0 讨论(0)
  • 2020-12-14 11:47

    The .value property applies to form elements (inputs), not divs. The simplest way to get the contents of your div element is with .innerHTML:

    document.getElementById('hour').innerHTML;
    
    0 讨论(0)
提交回复
热议问题