【问题标题】:jquery cookie plugin or code not working in pagejquery cookie 插件或代码在页面中不起作用
【发布时间】:2011-10-26 19:13:14
【问题描述】:

我的页面中有这段代码。

$(document).ready(function () {
            $("#ba_object_Code").change(function () { $("#HRBK").val($(this).val()); });
            $.cookie('cookie_name', 'cookie_value');
            if (sessid == 'xyz') {
                $("#ControlPlanID").removeAttr('disabled');
            }
            $(".t-grid-action.t-button.t-state-default.t-grid-add").click(function () {
                $.cookie('sessid', 'xyz');
            });

        });

我收到了这个错误

Microsoft JScript 运行时错误:对象不支持此属性或方法

【问题讨论】:

  • 你在包含jQuery之后是否包含jquery cookie插件?
  • 您收到的错误表明某些内容未正确包含。
  • 两件事:1. sessid 从未初始化(第 4 行) 2. 你在哪一行得到错误?

标签: javascript jquery jquery-cookie


【解决方案1】:

你没有定义 sessid,所以当你调用它时,它会失败。

查看工作示例:http://jsfiddle.net/zNDHN/

$(document).ready(function () {

            var sessid = $.cookie('sessid');

            $("#ba_object_Code").change(function () { $("#HRBK").val($(this).val()); });
            $.cookie('cookie_name', 'cookie_value');
            if (sessid == 'xyz') {
                $("#ControlPlanID").removeAttr('disabled');
                console.log('cookie_found');
            }
            $(".t-grid-action.t-button.t-state-default.t-grid-add").click(function () {
                $.cookie('sessid', 'xyz');
                console.log('cookie_created');
            });

        });

【讨论】:

【解决方案2】:

顺序很重要,jquery 文件必须包含在_layout.cshtml 中以防使用母版页...'JQuery' is undefined

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多