我有一个循环数组的函数......虽然它工作它似乎改变了从“开始”函数发送到“处理”函数的信息的值,但我不知道为什么......我确定我犯了一个愚蠢的错误,但我看不到错误=/
这是我的功能:
var array_data = data[9]; //global array to use
console.log(array_data); //debug
function process(i){
alert('Number is '+i); // shows the value "7" (should show value "1")
}
function begin(){
var count = 0;
for(i in array_data){
if(parseInt(array_data[i][9])){ //if true
var result = create_layout(i); //function to make the layout
alert('Number is '+i); //shows the value "1" (this is correct so far)
document.getElementById('result'+count).innerHTML = result;
document.getElementById('result'+count).onclick = function() { process(i); };
count++;
}
}
window.onload = function() {
begin();
};
以下是控制台日志中的 (array_data) 数组:
1: Array[10]
0: "Car One"
1: "1"
2: "3"
3: "d2.jpg"
4: "1"
5: "1"
6: "200"
7: "85"
8: "5000"
9: "1"
length: 10
7: Array[10]
0: "Car Two"
1: "1"
2: "1"
3: "e2.jpg"
4: "1"
5: "0"
6: "500"
7: "50"
8: "3000"
9: "0"
length: 10
所以我想知道为什么当它到达进程函数时它会改变“i”的值?