Basic webpack not working for button click function - Uncaught Reference error: undefined

后端 未结 1 426
终归单人心
终归单人心 2020-12-23 16:11

I have a basic HTML page with a button:




  ...


    
相关标签:
1条回答
  • 2020-12-23 16:45

    When you run the file over webpack, webpack will try not to litter the global scope and so the function will not be made available globally by default.

    If you want the function to be accessible outside the scope of he JS file, you should put it in the global scope.

    function uclicked() {
      // do something
    }
    window.uclicked = uclicked;
    

    Or just:

    window.uclicked = function() {
      // do something
    }
    
    0 讨论(0)
提交回复
热议问题