JavaScript array;
An array:
01.<script>
02. var colors = {
03. "1" : {
04. "a" : "#000000",
05. "b" : "#fdf6ed",
06. "c" : "#634322",
07. "d" : "#c8ab8f",
08. "e" : "#fdf6ed"
09. },
10.
11. "2" : {
12. "a" : "#ba8247",
13. "b" : "#ffffff",
14. "c" : "#634320",
15. "d" : "#c8ffff",
16. "e" : "#ffffff"
17. }
18. };
19.</script>
Display method:
01.function selvalue(v){
02. var arrays = colors[v];
03. for(description in arrays) {
04. document.getElementById(description+"color").value = arrays[description];
05. }
06.}
Effect, run the following code:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>javascript test</title>
<body>
<form action= "" method= "get" >
<select id= "Selheigh" name= "Selheigh" onchange= "Selvalue" (This.value); >
<option > Choose </option>
<option value= "1" > 001 </option>
<option value= "2" > 002 </option>
</select>
<br/>
A:<input name= "Acolor" id= "Acolor" type= "text" > <br/>
B:<input name= "Bcolor" id= "Bcolor" type= "text" > <br/>
C:<input name= "Ccolor" id= "Ccolor" type= "text" > <br/>
D:<input name= "Dcolor" id= "Dcolor" type= "text" > <br/>
E:<input name= "EColor" id= "EColor" type= "text" > <br/>
</form>
<script>
var colors = {
"1": {
"A": "#000000",
"B": "#fdf6ed",
"C": "#634322",
"D": "#c8ab8f",
"E": "#fdf6ed"
},
"2": {
"A": "#ba8247",
"B": "#ffffff",
"C": "#634320",
"D": "#c8ffff",
"E": "#ffffff"
}
};
function Selvalue (v) {
var arrays = Colors[v];
For (description in arrays) {
document.getElementById (description+ "Color"). Value = Arrays[description];
}
}
</script>
</body>