【问题标题】:IE Issue with jQuery and JSjquery 和 JS 的 IE 问题
【发布时间】:2013-02-10 16:36:52
【问题描述】:

我正在尝试编写一个函数,从篮子中转移物品并将其推入购物车。 我目前面临的问题是,虽然这段代码在 FF 和 Chrome 中运行良好,但它无法识别产品。

非常感谢。

var modals_pool = {};

$('.deal_order_btn').live('click', function (e) {
    e.preventDefault();

    deal = {};
    deal.id = $(this).attr('deal_id');
    deal.title = $(this).attr('deal_title');
    deal.items = [];
    additional_total = 0;
    $(this).parents('.deal_item_holder').find('table.deals_item_').each(function (index, ele) {
        item = {};
        item.id = $(ele).attr('deal_item_id');
        item.name = $(ele).find('.deal_item_name a').text();
        if ($(ele).find('select.product').length) {
            item.product = $(ele).find('select.product').val();
        }
        if ($(ele).find('select.product').length === 0) {
            item.product = $(ele).find('.deal_item_name a').attr('rel');
        }
        if ($(ele).find('select.size').length) {
            item.size = $(ele).find('select.size option:selected').text();
        }
        if ($(ele).find('.static_size').length) {
            item.size = $(ele).find('.static_size').text();
        }


        deal_object = modals_pool[$(ele).attr('container_id').replace(/ /g, '_') + "_" + $(ele).find('.product').val()];

        //console.log(deal_object);

        if ($(ele).find('select.product').length && deal_object) {




            item.product_name = $(ele).find('select.product :selected').text();

            item.product_topping = deal_object.selected_topping_normal;
            item.base = deal_object.default_base;


            item.product_double_topping = deal_object.selected_topping_double;


            item.product_total = deal_object.total;
            additional_total += deal_object.total;



        }


        deal.items.push(item);

    });



    deal.total = $(this).parents('li:first').find('span.customize_total_deal').text();
    deal.orginal = $(this).parents('li:first').find('span.customize_total_deal').attr('orginal_total');
    deal.addtional_topping_total = additional_total;

    $.post(window.location.href, {
        'action': '_saveUserDeal',
            'deal_details': JSON.stringify(deal)
    }, function (data) {
        if (data.code) {
            var date = new Date();
            var milseconds = date.getTime();
            $('.basket_box_holder').load(root + store_name + '/get_cart?' + milseconds);
        }
    });

});

【问题讨论】:

  • 您使用的是什么版本的 jQuery? live() 方法自 1.7 起已弃用,并在 1.9 中删除
  • 请随时访问此链接以获取实时版本:topspizza.co.uk/public/acton/deals
  • 无法识别产品”是什么意思,脚本的哪一部分没有按预期工作?我只能猜测 IE 拒绝解析所有那些自定义(和无效)的 HTML 属性。
  • 添加了标题和成本,但产品没有。
  • 因此产品被添加到购物篮,但如果您在 IE 中访问结帐,您将看到错误而不是产品名称。

标签: javascript jquery javascript-events shopping-cart


【解决方案1】:

您的脚本在第 683 行中断并出现错误:

对象不支持此操作

这是因为 item 是 Internet Explorer 8 及以下版本中的保留关键字,请尝试将其重命名为其他名称或使用 var 关键字在本地声明 item。这可能会解决它:

var item = {};

干杯。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-15
    相关资源
    最近更新 更多