我有两个相互冲突的 jQuery 文件。我收到了错误:
Uncaught TypeError: Object 0px has no method 'css'
经过多次调整和修补,我想出了如何解决这个问题。但是,我认为这不是一个适当的解决方案,我想获得有关替代适当解决方案的反馈。
这些文件是来自 1) 模板和 2) 幻灯片的 jQuery 插件文件;调整屏幕大小时调整容器和其他元素的大小。
问题的根源在于幻灯片 jquery 插件声明:
a.fn.css原始=a.fn.css;
每当调用 a[c].css("box-sizing") 或类似内容时,我都可以将错误读取到模板的 jquery 文件的行中。
我通过在整个模板的 jquery 函数文件中将 .css 替换为 .cssOriginal 来解决这个问题。但我感到不安。首先,幻灯片只会在某些页面中使用。
如何防止模板的 .css 调用受到幻灯片插件文件的影响?
幻灯片中的所有 jQuery 文件都包含一个 jQuery.noConflict(); 在最后。
从模板来看,这部分代码是冲突的根源:
e.matchHeight = function (a, c, f) {
var j = e(window),
h = a && b[a];
if (!h) {
var h = b[a] = {
id: a,
elements: c,
deepest: f,
match: function () {
var a = this.revert(),
b = 0;
e(this.elements).each(function () {
b = Math.max(b, e(this).outerHeight())
}).each(function (c) {
var d = "outerHeight";
"border-box" == a[c].css("box-sizing") && (d = "height");
var g = e(this),
c = a[c],
d = c.height() + (b - g[d]());
c.css("min-height", d + "px")
})
},
revert: function () {
var a = [],
b = this.deepest;
e(this.elements).each(function () {
var c = b ? e(this).find(b + ":first") : e(this);
a.push(c.css("min-height", ""))
});
return a
},
remove: function () {
j.unbind("resize orientationchange", k);
this.revert();
delete b[this.id]
}
}, k = function () {
h.match()
};
j.bind("resize orientationchange", k)
}
return h
};
从幻灯片来看,这部分代码是问题的根源:
a.fn.cssOriginal=a.fn.css;
a.fn.css=function(c,d){
var e=this,f={};
if(typeof c=="string")if(d)f[a.camelCase(c)]=d;
else return e.cssOriginal(c);
else f=c;
f=a.cssPropertySupporter(f);
var g=a("body").data("cssPerspective");
if(f.transform)a.each(b,function(a,b){var c=b+(b?"T":"t")+"ransform";
var d=f.transform;
f[c]=(g&&!/perspective/gi.test(d)?"perspective("+g+") ":"")+d});
e.cssOriginal(f);
return e
}
谢谢