Button click event binding in Electron js

前端 未结 1 810
别跟我提以往
别跟我提以往 2021-01-01 17:40

I have started using electron js to develop desktop application.

I want to know that how to bind button click event with javascript function so that I can perform ot

相关标签:
1条回答
  • 2021-01-01 18:44

    To explain this for future users. <script> tag's in an HTML document are executed in the global scope, this means that this === window, I.e. any function or variable declared in the script inherently becomes global.

    When you require a script it becomes isolated in it's own context (it is wrapped in another function so this !== window, I.e. any function or variable declared in the script is not available globally.

    The correct way to do this is to use require('./renderer.js') and to use this code

    function getData() {
        ...
    }
    
    document.querySelector('#btnEd').addEventListener('click', () => {
        getData()
    })
    
    0 讨论(0)
提交回复
热议问题