TypeError: getElementById is null

后端 未结 4 1396
野性不改
野性不改 2020-12-22 14:05

    
        

        
4条回答
  •  生来不讨喜
    2020-12-22 14:42

    You are executing javascript before your 'body' rendered. Thus document.getElementById("submit") would return null. Because there are no "submit" DOM element yet.

    One solution is to move your javascripts under 'body', Or use JQuery with

    $(document).ready(function() {
        ...
    });
    

    Your variable also has scope problem, your function cannot access variable declared outside this function with 'var' declaration. If you really need that variable, you should remove 'var' declaration. A better way is to move all your variable inside clicked function. like following code

    
        
        
    
        

    Project |

    | herbykit


    first desc.

提交回复
热议问题