をありがとう、あなたがこのような何かをしようと、単一の値で複数のデータ片を付けることができますので、あなたのドロップダウン値の区切りです:
<img id="image" src="Null_Image.png" /> <br />
<div id="fillText"> select something </div>
<select id="imgList">
<option value="1.png|some text for 1">Select Option</option>
<option value="2.png|other text here">One 1</option>
<option value="3.png|a fancy title">Two 2</option>
<option value="4.png|an interesting tidbit">Three 3</option>
</select>
<script>
function setClass() {
var img = document.getElementById("image");
var fillText = document.getElementById("fillText");
// generate an array by splitting the value on '|'
var values = this.value.split('|');
img.src = values[0]; // the first array value
fillText.innerHTML = values[1]; // the second array value
return false;
}
document.getElementById("imgList").onchange = setClass;
</script>
これはさせてくださいそのオプション値で作業するためにいくつかの項目をスタックします。それを分割して個別に使用することで、望ましい結果を達成できるはずです。
データをより複雑になる、オブジェクトに格納検討し、必要なデータを検索するためのキーとして、ドロップダウン値を使用する場合:
<img id="image" src="Null_Image.png" /> <br />
<div id="fillText"> select something </div>
<select id="imgList">
<option value="valueOne">Select Option</option>
<option value="valueTwo">One 1</option>
<option value="valueThree">Two 2</option>
<option value="valueFour">Three 3</option>
</select>
<script>
var lookupValues = {
'valueOne': {
'img':'1.png',
'txt':'some text for 1'
},
'valueTwo': {
'img':'2.png',
'txt':'other text here'
},
'valueThree': {
'img':'3.png',
'txt':'a fancy title'
},
'valueFour': {
'img':'4.png',
'txt':'an interesting tidbit'
}
};
function setClass() {
var img = document.getElementById("image");
var fillText = document.getElementById("fillText");
// get the lookup values with a key matching this.value
var values = lookupValues[this.value];
img.src = values['img']; // the 'img' value
fillText.innerHTML = values['src']; // the 'src' value
return false;
}
document.getElementById("imgList").onchange = setClass;
</script>
あなたはユニークな心配をせずに任意の複雑なデータを使用することができます。この方法区切り文字など
幸運!考慮すべき