简体   繁体   English

$ .noConflict,jquery.cookie和引导程序的问题

[英]Issue with $.noConflict, jquery.cookie, and bootstrap

I am trying to use jquery.cookie to handle all of my cookie needs. 我正在尝试使用jquery.cookie来处理我的所有cookie需求。 Whenever I try to create a cookie, I get the following error: 每当我尝试创建cookie时,都会出现以下错误:

Uncaught TypeError: Object function (e,t){return new x.fn.init(e,t,r)} has no method 'cookie'

I read to use $.noConflict() to fix this issue, which did indeed resolve the error above. 我读过使用$.noConflict()来解决此问题,确实确实解决了上述错误。 However, when I use it, I get errors thrown about bootstrap's .tooltip() , as well as $.sidr which I use for my slide out menu. 但是,当我使用它时,会出现关于bootstrap的.tooltip()以及用于滑出菜单的$.sidr

Does someone have some suggestions on resolving this? 有人对此有建议吗?

Thanks 谢谢

Once you invoke noconflict mode you can no longer reference jQuery with $ 一旦调用noconflict模式,就无法再使用$引用jQuery。

I usually do it like this: 我通常这样做:

$j = jQuery
$j.noConflict();


$j(function(){

    $j('yourSelector').tooltip();

});

There is probably a more efficient way than duplicating the jQuery function, suggestions are always welcome 可能有比复制jQuery函数更有效的方法,总是欢迎提出建议

I initially loaded jquery.cookie in the <head> of my site. 我最初在网站的<head>中加载了jquery.cookie。 Moving it to the very bottom fixed it. 将其移至最底端将其修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM