2011-10-23 39 views
1

JavaScript錯誤我得到這個錯誤,只能在IE中:只能在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:

這裏呈現的HTML代碼觸發的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> 

當複選框被點擊的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 dosent工作。我發現這http://www.sitepoint.com/forums/showthread.php?626340-jQuery-change()-event-in-IE-not-triggering-properly-with-checkbox

但我不知道如何實現它到我的代碼。

+0

哪個IE?你可以提供演示嗎? –

+4

問題是該項目不是一個DOM對象。所以真正的錯誤不在第56行,但在調用updateProductPrice的行上。 – topek

+0

我剛剛更新了函數和函數被調用的行的代碼。 – andkjaer

回答

0

我想這只不過是你忘了var

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

這將如何解決這個問題? –

+0

我不相信IE喜歡提及那些未定義的全局變量(窗口屬性)。 – Pointy

+0

IE不喜歡全局變量在函數中聲明嗎?這不會導致各種問題嗎? –