[英]Javascript member variable undefined
function Class() {
var self=this;
self.searchfield=$('#search');
self.resultbox=$('#searchresults');
self.onSearchFieldChanged=function() {
console.log("F: "+self.searchfield);
console.log("R: "+self.resultbox);
}
self.searchfield.live("keyup",self.onSearchFieldChanged);
}
var INSTANCE=null;
Class.init=function() {
INSTANCE=new Class();
}
$(document).bind("globalsloaded", Class.init);
As soon as I type something in #search input, the output on console is as following: 只要我在#search输入中输入内容,控制台上的输出如下:
F: undefined
R: undefined
So why are those two variables undefined? 那么为什么这两个变量未定义? They ARE in scope and should contain the corresponding jQuery objects.
它们在范围内,应包含相应的jQuery对象。
After 5 days of work I found the Problem: JQueryMobile 经过5天的工作,我发现了问题:JQueryMobile
What happens is: 会发生什么:
deviceready
event by phonegap deviceready
事件 domready
event domready
活动 input#search
element to reinsert it again, surrounded by some style divs input#search
#search元素以再次重新插入,由一些样式div包围 Now I am doing my initialization in the pageinit
event of JQM. 现在我在JQM的
pageinit
事件中进行初始化。 No problems anymore. 没问题了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.