Change label text using JavaScript

前端 未结 8 1177
后悔当初
后悔当初 2020-11-27 04:39

Why doesn\'t the following work for me?



        
8条回答
  •  伪装坚强ぢ
    2020-11-27 05:12

    Because your script runs BEFORE the label exists on the page (in the DOM). Either put the script after the label, or wait until the document has fully loaded (use an OnLoad function, such as the jQuery ready() or http://www.webreference.com/programming/javascript/onloads/)

    This won't work:

    
    
    

    This will work:

    
    
    

    This example (jsfiddle link) maintains the order (script first, then label) and uses an onLoad:

    
    
    

提交回复
热议问题