开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜