2010-11-17 110 views
0

的代碼是這樣的,是一個簡單的div水平滾動條:爲什麼這個jquery函數在IE6/7中不起作用?

var c = 0; 
$("#sezDati_imp_avanti").click(function (event) { 
    avantiImp(); 
    event.preventDefault(); 
}); 

function avantiImp() { 
    if (c == 0) { 
     $('#sezDati_scroller').animate({ 
      marginLeft: "-165px" 
     }, 500); 
     c = 1; 
    } else { 
     $('#sezDati_scroller').animate({ 
      marginLeft: "-" + (165 * c) + "px" 
     }, 500); 
     c++; 
    } 
} 

$("#sezDati_imp_indietro").click(function (event) { 
    //$('#sezDati_scroller').animate({ marginLeft: "165px"}, 500); 
    indietroImp(); 
    event.preventDefault(); 
}); 

function indietroImp() { 
    if (c == 0 || c == 1) { 
     $('#sezDati_scroller').animate({ 
      marginLeft: "0px" 
     }, 500); 

    } else { 
     $('#sezDati_scroller').animate({ 
      marginLeft: "-" + (165 * (c - 2)) + "px" 
     }, 500); 
     c--; 
    } 
} 

helppp! :-)

+0

爲什麼你會*不*縮進你的代碼?這總是浪費時間,並讓其他人閱讀時感到沮喪......並使他們不太可能幫助你。 – 2010-11-17 10:36:32

+0

什麼不起作用?有沒有錯誤? – rahul 2010-11-17 10:36:39

+0

不,沒有錯誤!....當我點擊div ID = sezDati_imp_avanti什麼都沒有發生... – Ste 2010-11-17 10:46:21

回答

1

在Internet Explorer中,eventwindow對象的成員。由於window是默認對象,因此可能與您的參數名稱有衝突。請嘗試使用其他名稱,如e

$("#sezDati_imp_indietro").click(function(e) { 
    //$('#sezDati_scroller').animate({ marginLeft: "165px"}, 500); 
    indietroImp(); 
    e.preventDefault(); 
}); 
+0

謝謝,但不工作... – Ste 2010-11-17 11:04:14

0

試試這個

var c = 0; 

function avantiImp() { 
    if (c == 0) { 
     $('#sezDati_scroller').animate({ 
      marginLeft: "-165px" 
     }, 500); 
     c = 1; 
    } else { 
     $('#sezDati_scroller').animate({ 
      marginLeft: "-" + (165 * c) + "px" 
     }, 500); 
     c++; 
    } 
} 

function indietroImp() { 
    if (c == 0 || c == 1) { 
     $('#sezDati_scroller').animate({ 
      marginLeft: "0px" 
     }, 500); 

    } else { 
     $('#sezDati_scroller').animate({ 
      marginLeft: "-" + (165 * (c - 2)) + "px" 
     }, 500); 
     c--; 
    } 
} 

$(function() { 

    $("#sezDati_imp_avanti").click(function (ev) { 
     avantiImp(); 
     ev.preventDefault(); 
    }); 

    $("#sezDati_imp_indietro").click(function (ev) { 
     //$('#sezDati_scroller').animate({ marginLeft: "165px"}, 500); 
     indietroImp(); 
     ev.preventDefault(); 
    }); 


}); 
+0

好的,我已經添加一個警報(三);進入兩個函數和警報工作...所以我認爲jquery動畫中有錯誤... – Ste 2010-11-17 11:22:15

相關問題