使用 javascript 调用 jquery 函数
Calling jquery function with javascript
我试图在 $(document).ready() 之外调用 fxn 函数,但我无法让它工作。它 returns ReferenceError: fxn is not defined.. 我错过了什么?
因为 jQuery 的工作方式。这个错误是可以预见的。
发生了什么,fxn
的声明正在等待文档实际准备好。调用此方法的地方不是。因此,通过尝试这样做,您实际上是在尝试调用一个尚不存在的函数。
根据:http://learn.jquery.com/using-jquery-core/document-ready/
A page can't be manipulated safely until the document is "ready."
jQuery detects this state of readiness for you. Code included inside
$( document ).ready()
will only run once the page Document Object
Model (DOM) is ready for JavaScript code to execute. Code included
inside $( window ).load(function() { ... })
will run once the entire
page (images or iframes), not just the DOM, is ready.
我试图在 $(document).ready() 之外调用 fxn 函数,但我无法让它工作。它 returns ReferenceError: fxn is not defined.. 我错过了什么?
因为 jQuery 的工作方式。这个错误是可以预见的。
发生了什么,fxn
的声明正在等待文档实际准备好。调用此方法的地方不是。因此,通过尝试这样做,您实际上是在尝试调用一个尚不存在的函数。
根据:http://learn.jquery.com/using-jquery-core/document-ready/
A page can't be manipulated safely until the document is "ready." jQuery detects this state of readiness for you. Code included inside
$( document ).ready()
will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute. Code included inside$( window ).load(function() { ... })
will run once the entire page (images or iframes), not just the DOM, is ready.