このスクリプトをオンラインで見つけました。それは私が必要とするほとんどのものです。見てみましょう:
<script type="text/javascript">
imageArray = new Array("NOimglink", "imglink", "imglink", "imglink");
altArray = new Array("", "Red Star", "Yellow Star", "Pink Star");
function show() {
var Index = document.menuForm.select1.options[document.menuForm.select1.selectedIndex].value;
var text = document.getElementById('select1').options[document.getElementById('select1').selectedIndex].text;
document.testStar.src = imageArray[Index];
document.testStar.alt = altArray[Index];
document.getElementById("item").innerHTML = document.getElementById("select1").value;
}
</script>
<div id="item"></div>
<form action="../action/return.html" method="post" id="menuForm" name="menuForm">
<select id="select1" onchange="show()" name="select1">
<option value="0" selected="selected">Choose a color</option>
<option value="1">Red Star</option>
<option value="2">Yellow Star</option>
<option value="3">Pink Star</option>
</select>
<img id="testStar" height="35" alt="red star" src="" width="35" border="0" name="testStar">
とにかく、すべての配列行を使用する以外に方法はありますか? imageArray と altArray ? 50 を超える選択オプションがありますが、配列が多すぎます。もっと簡単な方法はありますか?