我有一個wordpress網站與Woocommerce和WPML插件運行多語言。 在結帳頁面上,我有一個javascript錯誤(我對js不太好)。對象函數沒有方法(我不是一個JavaScript編碼器)
錯誤是:
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,我真的不知道該怎麼想。我知道「對象函數沒有方法」是一個常見的問題,我查看了其他帖子,但我無法想象它。
所以大家(和女孩),我需要幫助這一個。
感謝
布魯諾
嗨,非常感謝回答。這是我檢查的第一件事,它包含在
中。沒有404或類似的問題,沒關係。我檢查了螢火蟲和鍍鉻控制檯。 –@BrunoHug:它包含在jQuery之後嗎?還有其他的jQuerys嗎? – SLaks
它是在jquery(jQuery v1.8.3)之後。 是的,你是對的,還有另一個由主題加載(jQuery v1.7.1)。這可能是問題嗎? –