Why is a function declared in document.ready() not defined when called?

后端 未结 5 1938
逝去的感伤
逝去的感伤 2021-01-15 17:52

Here is my HTML/JavaScript:



        
5条回答
  •  南方客
    南方客 (楼主)
    2021-01-15 18:31

    Try this:

    $(function() {
        window.foo = function () {
            alert('bar');
        }
    });
    

    Basically, you need to expose the function to global scope.

提交回复
热议问题