????????window.onload=function()
????????{
????????????var?Box?=?document.getElementById("Box");
????????????var?Picture?=?document.getElementById("Picture");
????????????var?Button?=?document.getElementById("Button").getElementsByTagName("span");
????????????var?arrow_left?=?document.getElementById("arrow_1");
????????????var?arrow_right?=?document.getElementById("arrow_2");
????????????var?index?=?1;
????????????function?ShowButton()
????????????{
????????????????Button[index?-?1].className?=?"show";
????????????}
????????????function?Scroll(offset)
????????????{
????????????????var?NewLeft?=?parseInt(Picture.style.left)?+?offset;
????????????????Picture.style.left?=?NewLeft?+?"px"
????????????????if(NewLeft?>?-600)
????????????????{
????????????????????Picture.style.left?=?-1800?+?"px";
????????????????}
????????????????if(NewLeft?<?-1800)
????????????????{
????????????????????Picture.style.left?=?-600?+?"px";
????????????????}
????????????}
????????????arrow_left.onclick=function()
????????????{
????????????????index?+=?1;
????????????????ShowButton();
????????????????Scroll(600);
????????????}
????????????arrow_right.onclick=function()
????????????{
????????????????index?-=?1;
????????????????ShowButton();
????????????????Scroll(-600)
????????????}?
????????}
????????</script>報錯:TypeError: Button.NaN is undefined如題,寫到圓點跟隨圖片切換高亮的時候,這行代碼報錯了;我認為應(yīng)該是變量index為局域變量,無法在其他封裝函數(shù)里使用造成的,不知道是不是這樣……翻了下課程下面的答案,好像沒有和我情況遭遇一樣的同學(xué)。
Button[index - 1]報錯未定義。
Dryad安
2017-12-01 19:29:12