-1
是否有可能創建for循環創建函數(等)?只是爲了減少硬編碼,因爲我在數組中有很多值。我在這裏我的代碼,它不起作用。是否可以在創建函數時創建for循環?
var obj=["backupF31","backupF32","backupF33","backupF34","backupF35"];
for (var i = 0; i < obj.length; i++) {
function obj[i]()
{
var data = {};
$.ajax({type: 'POST', data: JSON.stringify(data), contentType: 'application/json',
\t \t \t \t \t url: '/legone/survey/'+obj[i]+'', \t \t \t \t \t \t
success: function(data) {
}
});
\t alert("Sucessful backup on "+obj[i]+");
}
}
從上面的代碼中,我只是想插入在obj中的數組的值[I]感謝