admin管理员组文章数量:1327960
I am using jQuery. I keep all of my function definitions wrapped in the $(document).ready event in application.js. I have a function from it that I would like to call somewhere in the body of the page I am working on.
I was wondering if there is some alternative to the .ready event that will work on a script load. Ideally I would like to do something like: $('application.js').ready( call function );
In the jQuery documentation it only mentions the $(document).ready call but I was wondering if this can be altered or if there is some plain javascript alternative.
I am using jQuery. I keep all of my function definitions wrapped in the $(document).ready event in application.js. I have a function from it that I would like to call somewhere in the body of the page I am working on.
I was wondering if there is some alternative to the .ready event that will work on a script load. Ideally I would like to do something like: $('application.js').ready( call function );
In the jQuery documentation it only mentions the $(document).ready call but I was wondering if this can be altered or if there is some plain javascript alternative.
Share asked Mar 17, 2010 at 15:17 unfloresunflores 1,8102 gold badges16 silver badges37 bronze badges 2- 2 Why $(document).ready doesn't suite you? – Andrew Bezzub Commented Mar 17, 2010 at 15:21
- Maybe I'm going about this the wrong way. In application.js the function was defined in the head wrapped by $(document).ready. I have an ajax call that only happens one page for the site so I wanted to call that function from within the page body. I wrapped the function call in $(document).ready as well. The function call is getting loaded before the function though. I would like a way to test the script load which will be after the page load. – unflores Commented Mar 17, 2010 at 15:52
2 Answers
Reset to default 5I think you’re looking for $.getScript
. This jQuery function loads a JavaScript file from the server using a GET
HTTP request and executes it. You can specify a callback function, to be executed after the script itself has been executed.
$.getScript('foo.js', function() {
alert('foo.js was loaded, do something cool now');
});
I am curious about this myself, but instinct would tell me you'd want to wait for the document to finish loading before running any javascript.
本文标签: jqueryRun a javascript function on script loadStack Overflow
版权声明:本文标题:jquery - Run a javascript function on script load - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742220582a2435381.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论