javascript change innerhtml

前端 未结 7 1907
逝去的感伤
逝去的感伤 2021-02-13 04:04

ok im new at javascript, but im trying to change the innerhtml of a div tag, heres my script and its not working:




        
7条回答
  •  -上瘾入骨i
    2021-02-13 04:43

    Rather than assigning var1 to window.onload, you're currently calling the function and storing its result. Also, this might be obvious, but var1 seems like an odd name for a function. Try this:

    function var1() {
      document.getElementById('text').innerHTML = 'hi';
    }
    
    window.onload = var1;
    

    Note the casing of onload, as well as the missing parentheses after var1.

提交回复
热议问题