[英]How can I get the value from one function into document ready?
I have 2 files. 我有2个档案。 File one calls a function in file 2. I can alert the value passed into file 2 if that function is outside of the document ready function. 文件1调用文件2中的一个函数。如果该函数超出文档就绪函数的范围,我可以警告传递给文件2的值。 I need that value inside of document ready. 我需要在文档中准备好该值。 Is there a way to do this? 有没有办法做到这一点?
file 1: 文件1:
setId(1);
file 2 文件2
function setId(v){
alert(v); // This works
}
If I place the function within the document ready function, I can no longer access the value passed in to it. 如果将函数放在文档就绪函数中,则无法再访问传递给它的值。
use the following code define setId function 使用以下代码定义setId函数
window.setId = function(v){
alert(v);
}
EDIT: Method 2 from Nick 编辑:尼克的方法2
window.myapp = window.myapp || {};
myapp.setId = function(v){
alert(v);
}
to call the setId function 调用setId函数
myapp.setId("test");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.