admin管理员组文章数量:1336660
As the title suggested, I'm trying to call the $(document).ready(function() {...}); from another file. The code snippet is as below:
Source file:
$(document).ready(function () {
alert('document.ready function called!');
// a lot of code
}
And in the test file:
TestFile.prototype.testDocumentReadyContents = function () {
// test code here trying to call the document.ready function
}
I haven't had any success on it yet. I have tried document.ready.apply(), trigger('ready'), overriding the document.ready function... but just couldn't call it. FYI I'm invoking it as part of my unit test.
Thanks.
As the title suggested, I'm trying to call the $(document).ready(function() {...}); from another file. The code snippet is as below:
Source file:
$(document).ready(function () {
alert('document.ready function called!');
// a lot of code
}
And in the test file:
TestFile.prototype.testDocumentReadyContents = function () {
// test code here trying to call the document.ready function
}
I haven't had any success on it yet. I have tried document.ready.apply(), trigger('ready'), overriding the document.ready function... but just couldn't call it. FYI I'm invoking it as part of my unit test.
Thanks.
Share Improve this question asked Dec 9, 2009 at 0:41 BeraCimBeraCim 2,3478 gold badges50 silver badges78 bronze badges 2- What exactly do you mean by "another file"? Another JS file? An IFrame? An Ajax Request? – Pekka Commented Dec 9, 2009 at 0:52
- @ Pekka: source file is a .js file. test file is also another .js file. Their includes are in a configuration file which works. – BeraCim Commented Dec 9, 2009 at 0:55
1 Answer
Reset to default 9GOOD WAY
$(document).ready(documentReady);
function documentReady() {
alert('document.ready function called!');
// a lot of code
}
TestFile.prototype.testDocumentReadyContents = function () {
documentReady();
}
Hackish Way
TestFile.prototype.testDocumentReadyContents = function () {
$.readyList[0]();
}
本文标签: javascriptCalling (document)ready(function() ) from another fileStack Overflow
版权声明:本文标题:javascript - Calling $(document).ready(function() {...}); from another file - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742417781a2471050.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论