我有這樣一個動態的變量:如何在元素列表之後使用動態變量而不丟失]?
var oneButton= null;
var oneMoreButton= null;
var differentNameButton= null;
var anotherButtonDifferent= null;
然後,我有這樣的:
switch(valor){
case 0:data = "oneButton"; break;
case 1:data = "oneMoreButton";break;
case 2:data = "differentNameButton";break;
case 3:data = "anotherButtonDifferent";break;
}
於是最後我有這樣的:
switch(anotherValor){
case 1:eval(data + ' = ' + document.getElementById('oneNameDiv').parentNode);break;
case 2:eval(data + ' = ' + document.getElementById('anotherDivName').parentNode);break;
case 3:eval(data + ' = ' + document.getElementById('oneMoreDivWithDifferentName').parentNode);break;
case 4:eval(data + ' = ' + document.getElementById('hereIsAnotherDivName').parentNode);break;
}
後,我試着執行它時,我得到在Firefox的錯誤控制檯:
missing ] after element list
http://localhost:8090/myapplication/functions.js
test1 = [objectHTMLDivElement]
有人知道發生了什麼?
聽說過一個數據結構,稱爲'Array'? –
在全球範圍內,你想要做什麼? – TJHeuvel
即時通訊不使用數組來簡化...即時通訊不使用類似數組[x]的東西,因爲我不能這樣做...什麼即時通訊試圖做的正是我已經exaplined ....我有一些變數,我之前宣佈...然後我需要把每個變量的div ... – Igor