2010-08-18 54 views
0

你好,我有這個代碼在Firefox中工作完美,但在IE 8不起作用,不給我任何錯誤?!IE的jquery問題在FF工作正常

$(".shp_div").change(function() { 
    var str = ""; 
    $("select option:selected").each(function() { 
     var countprod =parseInt($("#countprod").val()); 
     var str2 = $(this).val(); 
     str2_array = str2.split('|'); 
     var cost = parseInt(str2_array[0]); 
     var cost_extra = parseInt(str2_array[1]); 
     if ($("#countprod").val()>1) { 
     str = parseInt(((countprod-1)*cost_extra) + cost); 
     } else{ 
     str = cost; 
     }}); 
    $(".csq_item2").text(str); 
    var total =parseInt($("#subtotal").val()); 
    var shipping=parseInt(str + total); 
    $(".price_total").text(shipping); 
}) 
.change(); 

爲了獲得「全貌」請去爲:http://poshsunglasses.net/21-Bottega_Veneta-B.V.88.html,並添加到購物車督促,然後在購物車頁面上嘗試在FF選擇送貨的國家做出的計算在IE沒有。

謝謝

+0

可能與您的問題無關,但您應該小心使用'parseInt'而不指定基數。如果要解析的字符串以「0x」或「0」開頭,則該字符串將分別解析爲十六進制或八進制。請參閱https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/parseInt。 – 2010-08-18 09:29:12

回答

3

您的問題是您將更改事件綁定到DIV。 div's沒有真正的變化事件。也許在FF和鉻選擇更改事件漏槽低於但在IE瀏覽器它不。

嘗試將更改事件放在select(或另一個輸入)而不是div上。

順便說一句:你爲​​什麼要選擇一個foreach?當你只能選擇一個?

我這樣做:給畝選擇列表的一個id:

<select name="shipping" id="shipping"> 

$("#shipping").change(function() { 
    var str2 = $("option:selected","#shipping").val().split('|'); 
    var cost = parseInt(str2_array[0]); 
    var cost_extra = parseInt(str2_array[1]); 
    //Go on from here 
}); 

PS:如果你想在你的選擇列表的的信息使用的任何值發送到後端。我會用一個唯一的ID,而不是這個符號以防止出現問題,並把價格值一個額外的參數:

<option value="56411-416(unique ID)" price="25|10">Country</option> 
0

我改變

$(".shp_div").change(function() { 

$(".shippinginfo").change(function() { 

,並工作

相關問題