仅在 IE 中出现 JavaScript 错误

发布于 2024-12-11 14:44:32 字数 4539 浏览 0 评论 0原文

我收到此错误,仅在 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

但是我不知道如何将其实现到我的代码中。

I get this error, only in IE:

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

Javascript code:

    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()));
  };

Anyone?


EDIT 1:

Here is the rendered HTML code that triggers the javascript:

<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>

When the Checkbox is clicked the javascript is called.

Here is the full javascript code:

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);
};

EDIT 2:

I got rid of the nasty errors, so now I "only" have one more problem.
This function, wont fire in IE7, IE8

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

I suspect the it is the "change" that dosent work in IE. I have found this http://www.sitepoint.com/forums/showthread.php?626340-jQuery-change()-event-in-IE-not-triggering-properly-with-checkbox

But I don't know how to implement it into my code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丘比特射中我 2024-12-18 14:44:32

我认为这只是你忘记了var

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

I think it's simply that you forgot var !

var wrapper = $(item).parents('.advertising_product');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文