仅在IE中的javascript错误

时间:2011-10-23 18:35:37

标签: javascript jquery internet-explorer

我收到此错误,仅在IE中显示:

Object doesn't support this property or method
Line: 56
Sign: 5
Code: 0

Javascript代码:

    function recalcTotalPrice(item) {
    values = $("input", item).serialize();
    $.post( url,
           values,
           function (data,textStatus, jqXHR) {
              variant_wrapper = $(item).parents(".variant");
              $(".price", variant_wrapper).html(data.total_price);
56:           updateProductPrice(item);
           })
  };

  function updateProductPrice(item) {
    wrapper = $(item).parents('.advertising_product');
    $(".total_price", wrapper).html(sum($(".price", wrapper).map(function() {return parseFloat($(this).html())}).toArray()));
  };

任何?


编辑1:

以下是触发javascript的呈现HTML代码:

<li>
        <label class="month" for="month">Mar</label>
          <div class="week ">
            <input id="386_1_10" name="book[]weeks[]" style="display: none;" type="checkbox" value="1|10" />
            <label for="386_1_10">10</label>
          </div>
          <div class="week ">
            <input id="386_1_11" name="book[]weeks[]" style="display: none;" type="checkbox" value="1|11" />
            <label for="386_1_11">11</label>
          </div>
          <div class="week ">
            <input id="386_1_12" name="book[]weeks[]" style="display: none;" type="checkbox" value="1|12" />
            <label for="386_1_12">12</label>
          </div>
          <div class="week ">
            <input id="386_1_13" name="book[]weeks[]" style="display: none;" type="checkbox" value="1|13" />
            <label for="386_1_13">13</label>
          </div>
      </li>

<script>
  $('#item_386.week_picker_wrapper').weekPicker(
      {
          url: '/products/100/items/386/calc_total_price'
       }
    );
</script>

单击复选框时,将调用javascript。

以下是完整的JavaScript代码:

jQuery.fn.weekPicker = function(options) {
  var self = this;
  var week_picker = new WeekPicker(options, self);
}

jQuery.fn.weekLocker = function() {
  var self = this;
  var week_picker = new WeekLocker(self);
};

WeekPicker = function(options, selector) {

  var url = options.url;
  var yearPos = 0;

  $("a.prev_year", selector).click(function() {
    if (yearPos > 0) {
      $(".year", selector).css("margin-left", --yearPos * -55)
      $(".week_picker", selector).css("margin-left", yearPos * -185)
    }
    return false;
  })

  $("a.next_year", selector).click(function() {
    if (yearPos < 2) {
      $(".year", selector).css("margin-left", ++yearPos * -55)
      $(".week_picker", selector).css("margin-left", yearPos * -185)
    }
    return false;
  })

  $(".disabled input[type='checkbox'], .busy input[type='checkbox'], .locked input[type='checkbox']", selector).click(function () {
    return false;
  })

  $("input[type='checkbox']", selector).change(function() {
    recalcTotalPrice(selector);
  });

  function getValues(selection) {
    return selection.map(function() {return $(this).html()}).toArray().join(",")
  }

  function recalcTotalPrice(item) {
    values = $("input", item).serialize();
    $.post( url,
           values,
           function (data,textStatus, jqXHR) {
              variant_wrapper = $(item).parents(".variant");
              $(".price", variant_wrapper).html(data.total_price);
              updateProductPrice(item);
           })
  };

  function updateProductPrice(item) {
    var wrapper = $(item).parents('.advertising_product');
    $(".total_price", wrapper).html(sum($(".price", wrapper).map(function() {return parseFloat($(this).html())}).toArray()));
  };

  function sum(arr) {
    for(var s = 0, i = arr.length; i; s += arr[--i]);
    return s;
  };

  recalcTotalPrice(selector);
};

编辑2:

我摆脱了令人讨厌的错误,所以现在我“只”还有一个问题。 这个功能,不会在IE7,IE8中启动

$("input[type='checkbox']", selector).change(function() {
    recalcTotalPrice(selector);
  });

我怀疑这是在IE中工作的“变化”。我找到了这个http://www.sitepoint.com/forums/showthread.php?626340-jQuery-change()-event-in-IE-not-triggering-properly-with-checkbox

但我不知道如何在我的代码中实现它。

1 个答案:

答案 0 :(得分:0)

我认为只是你忘了var

var wrapper = $(item).parents('.advertising_product');