jQuery UI Widget Factory - IE8丢失了公共方法的上下文

时间:2012-04-19 02:08:59

标签: jquery jquery-ui widget factory

驾驶我屁股。以下是一个非常简单的jQuery UI Widget Factory插件示例,它在Chrome中运行得非常好。

(function($){
    $.widget("enstratus.panel", {
        options: {
            debug: false
        },

        open: function() {
            log('panel open');
            this.element.show();
        },

        close: function() {
            log('panel close');
            this.element.hide();
        },

        _create: function() {
            log('panel created');
        },

        _init: function() {
        }
    });
})(jQuery);

包含一些内容的div。

<div id="mypanel">Some redundant text.</div>

现在在页面上简单调用a)激活插件并b)调用插件上的方法。

var mypanel = $("#mypanel").panel();
mypanel.panel("open");

在IE8中没有错误而失败。如果你记录;

this.element.attr('id')

它呈现插件元素的正确ID。

如果你尝试;

this.element.addClass('testclass');
this.element.css('background', '#000');

什么都不适用 - 没有错误。

如果你;

$("#" + this.element.attr('id')).addClass('testclass');

有效。

出于某种原因 - 失去了背景,我不知道为什么。

我不能为我的生活找出原因。脚本标签都有type =“text / javascript”。 Doctype是为HTML5设置的(即)。

我不知所措 - 帮助!

0 个答案:

没有答案
相关问题