所以我试图创建一个颜色字符串数组,下拉列表的选项值等于数组的索引,但是当我警告整个数组或只是一个返回未定义的值时。
function band(col, num, snum) {
var color = new Array(col,"");
var nmbr = num;
var strn = snum;
this.getColor = function() {
return color;
};
this.getNum = function() {
return nmbr;
};
this.getStrn = function() {
return strn;
};
}
var opis_r1 = new band("black", "", "");
var opis_r2 = new band("black", "", "");
var opis_r3 = new band("gold", "", "");
var opis_r4 = new band("gold", "", "");
var opis_r5 = new band("brown", "", "");
var resistance = "";
var resistance2 = "";
opis_r1.color[1] = "brown";
opis_r1.color[2] = "red";
opis_r1.color[3] = "orange";
opis_r1.color[4] = "yellow";
opis_r1.color[5] = "green";
opis_r1.color[6] = "blue";
opis_r1.color[7] = "violet";
opis_r1.color[8] = "grey";
opis_r1.color[9] = "white";
/*for (var i = 1; i < opis_r1.color.length; i++) {
opis_r2.color[i] = opis_r1.color[i];
}*/
opis_r2.color=opis_r1.color;
opis_r3.color[1] = "black";
opis_r3.color[2] = "brown";
opis_r3.color[3] = "red";
opis_r3.color[4] = "orange";
opis_r3.color[5] = "yellow";
opis_r3.color[6] = "greeen";
opis_r3.color[7] = "blue";
opis_r3.color[8] = "violet";
opis_r4.color[1] = "silver";
opis_r4.color[2] = "no color";
opis_r5.color[1] = "red";
opis_r5.color[2] = "orange";
opis_r5.color[3] = "yellow";
opis_r5.color[4] = "no color";
function hop2() {
alert("hop");
alert(opis_r1.color[0]);
gen_res_count();
}
function gen_check() {
var res;
var temp, temp1;
temp = opis_r1.color[document.forms['std_res_gen'].R11.value] + " - "+opis_r2.color[document.forms['std_res_gen'].R22.value] + " - " + opis_r3.color[document.forms['std_res_gen'].R33.value] + " - ";
res = temp;
return res;
}
function gen_res_count() {
if ((document.forms['std_res_gen'].R11.value == '?') || (document.forms['std_res_gen'].R22.value == '?') || (document.forms['std_res_gen'].R33.value == '?') || document.forms['std_res_gen'].R44.value == '?' || document.forms['std_res_gen'].R55.value == '?') {
window.alert("Choose values at all fields.");
document.forms['std_res_gen'].T33.value = "";
}
else {
resistance2 = gen_check();
alert("rcount");
gen_explain();
}
}
function gen_explain() {
document.forms['std_res_gen'].T33.value = resistance2 + opis_r4.color[document.forms['std_res_gen'].R44.value] + " - " + opis_r5.color[document.forms['std_res_gen'].R55.value];
}