我想要做的是啓用for()
內的多個複選框。現在看起來像這樣,但從我所學到的,你不能從這樣的變量運行命令,我不能運行,(例如)cab_type_value = "whatever"
。我也不能跑road_load_enabled
;它只是不起作用。有人如何我可以做到這一點?我如何解析document.MyForm.InputName.disabled
中的var J
?JavaScript,如何將一個變量解析爲命令?
for(var j=1; j<=14; j++) {
var cab_type_value = "document.exe_mode_form.cab_type" + j + ".value";
var cab_type_checked = "document.exe_mode_form.cab_type" + j + ".checked == 1";
for(var i=1; i<=document.exe_mode_form.road_load_number.value; i++) {
var road_load_value = "document.exe_mode_form.load" + i + ".value";
var road_load_enabled = "document.exe_mode_form.load" + i + ".disabled = false";
var road_load_disabled = "document.exe_mode_form.load" + i + ".disabled = true";
var rld_db = "document.exe_mode_form.a" + i + "_a1.value";
if (cab_type_checked) {
if (test == 1) {
if(road_load_disabled) {
alert("road_load_disabled");
road_load_enabled;
}
test = 2;
}
if(cab_type_value == rld_db) {
if(olof == 1) {
alert("cab_type_value == rld_db");
olof = 2;
}
road_load_enabled;
}
}
}
}
而且,這部分是不工作:
if(cab_type_value == rld_db) {
if(olof == 1){
alert("cab_type_value == rld_db");
olof = 2;
}
road_load_enabled;
}
而且我已經檢查,cab_type_value
具有相同的值rld_db
。
可能的重複[將變量放入函數javascript的名稱](http://stackoverflow.com/questions/4925949/putting-a-variable-進入功能名稱的JavaScript) – Quentin 2012-07-19 14:46:17
那麼有正確的方法和錯誤的方式。這是錯誤的:https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/eval – 2012-07-19 14:46:41
爲什麼所有的命令都在引號中? – varela 2012-07-19 14:47:06