【问题标题】:Why jQuery Cookie Plugin is not working on a particular page?为什么 jQuery Cookie 插件在特定页面上不起作用?
【发布时间】:2012-08-09 11:31:56
【问题描述】:

我正在使用 jQuery Cookie 插件,它在除主页之外的所有页面上都可以正常工作,以运行该页面我正在敲我的头,但没有运气。

我的代码如下:

$.cookie('CA_txtKeywords', $("#CAT_txtKeywords").val(), { expires: 7, path: '/' });

在萤火虫中说:

Uncaught TypeError: Object function (a,b){return new e.fn.init(a,b,h)} has no method 'cookie'

谁能指导一下这个错误是什么以及如何删除它?

【问题讨论】:

    标签: javascript jquery cookies


    【解决方案1】:

    您在脑海中包含 jQuery,然后您包含 cookie 插件,但在页面底部您会看到:

            <script type="text/javascript" src="http://www.google.com/jsapi"></script>
            <script type="text/javascript">
      // You may specify partial version numbers, such as "1" or "1.3",  with the same result. Doing so will automatically load the latest version matching that partial revision pattern 
      // (e.g. 1.3 would load 1.3.2 today and 1 would load 1.4.1).
      google.load("jquery", "1");
    
      google.setOnLoadCallback(function() {
        // Place init code here instead of $(document).ready()
    $(".euro").parseNumber({format:"#,###", locale:"it"});
    $(".euro").formatNumber({format:"#,###", locale:"it"});
    
    })
    </script>
    

    使用谷歌加载器再次加载 jQuery。因为您再次加载 jQuery,所以直接附加到文档头部的 jQuery 命名空间(而不是原型)的任何内容都会被删除。

    所以归根结底,你到底为什么要加载 jQuery 两次?

    解决方案:

    删除 google 加载器并请求它从主页的页脚加载 jQuery。

    【讨论】:

      【解决方案2】:

      您确定插件已加载到您的主页上吗?你查过源头吗? 您也可以在 firebug 中检查加载的脚本。

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-19
      • 1970-01-01
      • 1970-01-01
      • 2013-06-30
      • 2015-08-16
      相关资源
      最近更新 更多