2012-09-13 42 views
0

我有以下代碼。面向對象的Javascript代碼不能在IE7中工作

function radioButtons() { 

var _inputCount; 
var _inputParentCount; 
var _radioInput; 

return { 

    inputCounter:function(groupId){ 

     _inputCount = $(groupId).find("input"); 
     _inputParentCount = $(_inputCount).parent(); 

     for(i = 0; i < _inputParentCount.length; i++){ 
      $(_inputParentCount[i]).attr("id", groupId + [i]); 
     } 

    }, 

    radioAction:function(radioButton){ 

     _radioInput = $(radioButton).find("input"); 

     for(i = 0; i < _inputCount.length; i ++){ 

      $(_inputCount[i]).parent().removeClass("selected"); 
      $(_inputCount[i]).attr("value", "false"); 

     } 


     $(radioButton).addClass("selected"); 
     $(_radioInput).attr("value", "true"); 
    }, 



}; 
}; 

var radioButtonsOne = new radioButtons(); 

$(document).ready(function(){ 
radioButtonsOne.inputCounter("#radioButtonsGroup"); 
}); 

它是我爲自定義單選按鈕編寫的自定義函數。我有一個類似的複選框按鈕。除了IE7之外,它在所有瀏覽器中都能正常工作。它告訴我radioButtonsOne沒有被定義。但它是。任何想法爲什麼?

謝謝!

+1

見http://stackoverflow.com/questions/5139205/javascript-can-a-comma-occur-after-the-last-一組數值集 – simon

回答

5

變化

$(radioButton).addClass("selected"); 
     $(_radioInput).attr("value", "true"); 
    }, 

刪除,

$(radioButton).addClass("selected"); 
     $(_radioInput).attr("value", "true"); 
    } 
+0

不錯!實際上,當對象的最後一個鍵後跟一個逗號時,IE7會引發異常。 – MaxArt

+0

非常感謝!這工作!感謝您及時的回覆! – Gezzasa