我有一个使用 Woocommerce 和 WPML 多语言插件运行的 wordpress 网站。 在结帐页面上,我遇到了 javascript 错误(而且我不擅长 js)。
错误是:
Uncaught TypeError: Object function (a,b){return new e.fn.init(a,b,h)} has no method 'removeCookie'
这里是错误的地方:
jQuery(document).ready(function(){
if(jQuery.cookie != undefined) {
// Check if cookie are enabled
jQuery.cookie('wpml_browser_redirect_test', '1');
var cookie_enabled = jQuery.cookie('wpml_browser_redirect_test') == 1;
jQuery.removeCookie('wpml_browser_redirect_test');
...
这是具有函数的文件:
(function ($, document, undefined) {
var pluses = /\+/g;
function raw(s) {
return s;
}
function decoded(s) {
return decodeURIComponent(s.replace(pluses, ' '));
}
$.cookie = function (key, value, options) {
// key and at least value given, set cookie...
if (value !== undefined && !/Object/.test(Object.prototype.toString.call(value))) {
options = $.extend({}, $.cookie.defaults, options);
if (value === null) {
options.expires = -1;
}
if (typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date();
t.setDate(t.getDate() + days);
}
value = String(value);
return (document.cookie = [
encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value),
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
options.path ? '; path=' + options.path : '',
options.domain ? '; domain=' + options.domain : '',
options.secure ? '; secure' : ''
].join(''));
}
// key and possibly options given, get cookie...
options = value || $.cookie.defaults || {};
var decode = options.raw ? raw : decoded;
var cookies = document.cookie.split('; ');
for (var i = 0, parts; (parts = cookies[i] && cookies[i].split('=')); i++) {
if (decode(parts.shift()) === key) {
return decode(parts.join('='));
}
}
return null;
};
$.cookie.defaults = {};
$.removeCookie = function (key, options) {
if ($.cookie(key, options) !== null) {
$.cookie(key, null, options);
return true;
}
return false;
};
})(jQuery, document);
因为我不懂javascript,所以我真的不知道该怎么想。我知道“对象函数没有方法”是一个常见问题,我看过其他帖子,但我想不通。
伙计们(和女孩们),我需要这方面的帮助。
谢谢
布鲁诺
最佳答案
如果您不包含任何 jQuery.cookie 插件,就会发生这种情况。
关于javascript - 对象函数没有方法(我不是 javascript 编码器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17558906/