JQuery小部件无法在Firefox中加载 - .attr('class')未定义

时间:2011-12-19 06:09:31

标签: jquery jquery-ui

我一直在指http://james.padolsey.com/javascript/inettuts-with-cookies/创建小部件。我提取了所有文件并将它们放入正确的目录中。但是,当我运行代码时,我收到此错误$(clonedWidget).attr("class") is undefined 我正在使用ajax调用加载窗口小部件内容。此错误现在不呈现任何窗口小部件的内容。在修改保存首选项的代码之前,小部件工作正常。 Previoulsy我提到http://nettuts.com/tutorials/javascript-ajax/inettuts/创建小部件 这是inettuts.js代码的一部分,它给出了错误:

sortWidgets : function () {
        var iNettuts = this,
            $ = this.jQuery,
            settings = this.settings;

        /* Read cookie: */
        var cookie = $.cookie(settings.saveToCookie);
        if(!settings.saveToCookie||!cookie) {
            /* Get rid of loading gif and show columns: */
            $('body').css({background:'#000'});
            $(settings.columns).css({visibility:'visible'});
            return;
        }

        /* For each column */
        $(settings.columns).each(function(i){

            var thisColumn = $(this),
            widgetData = cookie.split('|')[i].split(';');

            $(widgetData).each(function(){
                if(!this.length) {return;}
                var thisWidgetData = this.split(',');
                    clonedWidget = $('#' + thisWidgetData[0]),
                    colorStylePattern = /\bcolor-[\w]{1,}\b/,
                    thisWidgetColorClass = $(clonedWidget).attr('class').match(colorStylePattern);

                /* Add/Replace new colour class: */
                if (thisWidgetColorClass) {
                    $(clonedWidget).removeClass(thisWidgetColorClass[0]).addClass(thisWidgetData[1]);
                }

                /* Add/replace new title (Bring back reserved characters): */
                $(clonedWidget).find('h3:eq(0)').html(thisWidgetData[2].replace(/\[-PIPE-\]/g,'|').replace(/\[-COMMA-\]/g,','));

                /* Modify collapsed state if needed: */
                if(thisWidgetData[3]==='collapsed') {
                    /* Set CSS styles so widget is in COLLAPSED state */
                    $(clonedWidget).addClass('collapsed');
                }

                /* Modify closed state if needed: */                
                if(thisWidgetData[4]==='closed') {
                    /* Set CSS styles so widget is in CLOSED state */
                    $(clonedWidget).addClass('closed');
                }

                $('#' + thisWidgetData[0]).remove();
                $(thisColumn).append(clonedWidget);
            });
        });

        /* All done, remove loading gif and show columns: */
        $('body').css({background:'#000'});
        $(settings.columns).css({visibility:'visible'});
    }  

我已将id放到我的所有小部件上,但即使这样也无法解决此问题。这个问题只出现在firefox而不是IE中。有谁知道可能导致这种情况的原因?

0 个答案:

没有答案