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

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

Here is my HTML/JavaScript:



        
5条回答
  •  执念已碎
    2021-01-15 18:26

    You're placing the function's scope within another function, basically.

    Picture this:

    
    

    That is the facsimile of what you're trying to accomplish. Just like variables defined within a function are off limits outside of it, function names take on the same characteristics.

    Side-Note JavaScript doesn't require $ prefix on variable names (though is acceptable as far as names are concerned). I didn't know if you're coming from PHP and are just accustomed or were aware.

    Thought I'd make my comment an answer.

提交回复
热议问题