【问题标题】:Extending JQuery - IE Error Only - Object doesn't support this property or method扩展 JQuery - 仅 IE 错误 - 对象不支持此属性或方法
【发布时间】:2010-10-23 07:14:42
【问题描述】:

IE 唯一的错误...去看看...

当我执行此操作时,我得到 Object 不支持此属性或方法...

$('#the-content').showAsModal({
     'leftPosition': 100,
     'topPosition': 200,
     'centerX': true
});

我像这样扩展了 jQuery...

(function ($) {
    $.fn.showAsModal = function (options) {
        var settings = $.extend({
            'leftPosition': 0,
            'topPosition': 0,
            'transition': 'none',
            'transitionSpeed': 500,
            'zIndex': 9001,
            'centerX': false,
            'centerY': false
        }, options || {});

        return this.each(function () {
            var self = $(this)
            if (settings.centerY) settings.y = Math.floor((($(document).height() - self.height()) / 2);
            if (settings.centerX) settings.x = Math.floor(($(document).width() - self.width()) / 2);

            self.css({ 'position': 'absolute', 'top': settings.y + "px", 'left': settings.x + "px", 'z-index': settings.zIndex });

            if (self.parent('.modal-container').length <= 0)
                self.wrap("<div style=\"display:none;\" class=\"modal-container\"></div>");
            if (self.siblings('.modal-mask').length <= 0)
                self.parent().append("<div style=\"width:" + $(document).width() + "px;height:" + $(document).height() + "px;\" class=\"modal-mask\"></div>");
            self.parent().show().end();
        });
    };

    $.say = function () {

    };
})(jQuery);

我正在导入 JQuery,然后导入一个仅包含上述 sn-p 的文件。

这在 Firefox 中效果很好。

让我们开始一项计划,阻止人们访问我们使用 IE 的网站。如果我们都这样做......

【问题讨论】:

    标签: jquery internet-explorer


    【解决方案1】:

    您的代码中有语法错误,因此您的代码在任何浏览器中都不起作用。

    if (settings.centerY) settings.y = Math.floor((($(document).height() - self.height()) / 2);
    

    Math.floor 后面的 3 个括号中的一个太多了

    【讨论】:

    • 哇 - 当我现在读回这个问题时,它是如此明显.. 奇怪的是它在 FF 中工作。一定是在缓存什么的。
    猜你喜欢
    • 2011-02-02
    • 2011-04-27
    • 2011-08-25
    • 1970-01-01
    • 2011-02-14
    • 2011-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多