jQuery object reference is empty
var quiz = {
开发者_如何学编程 config : {
qType : $j('#questionTypeDdown')
},
data : {
qType : 'test'
},
init: function() {
quiz.assignUIActions();
},
assignUIActions : function() {
var c = quiz.config;
var d = quiz.data;
quiz.assignqType(c,d);
},
assignqType : function(c,d) {
console.log(c.qType);
console.log(d.qType);
}
};
$j(document).ready(function() { quiz.init(); });
console.log(c.qType)
returns an empty jQuery object but
console.log(d.qType)
returns the value 'test'
Please explain why this is happening and what is the right way to get reference to #questionTypeDdown
.
You're running qType : $j('#questionTypeDdown')
before the document is loaded.
You need to execute your object initializer in $j(document).ready
.
精彩评论