javascript onsubmit not working

前端 未结 2 2088
半阙折子戏
半阙折子戏 2021-02-12 19:28

I am trying to make a javascript function work on submitting the form, the function doesnt seem to run. Can anyone help?



    

        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-12 20:14

    When attaching the event handler to the form element, the scope of the event handler is the form and not the window

    As input elements inside a form are attached as properties to the form object, where the name is the key, calling upload() in the event handler, where the scope is the form, would equal calling form.upload(), but the form already has an element with that name so form.upload is the upload button, not the upload() function in the global scope.

    To solve it, either rename the function or the element

    
    
        
    
    
        
        
        
        
    
    
    

    FIDDLE

提交回复
热议问题