ドロップダウンメニューで人が何を選ぶかに応じて、画像を切り替えようとしています。html と js は 2 つの異なるファイルにあります。
これは html の一部です。
<select id="Breed_0_field" name="Breed76" onChange="javascript: wizard();" onkeyup="javascript: wizard();" tabindex="4">
<option selected="selected" value="Select One">Select One</option>
<option value="Other/Mix">Other/Mix</option>
<option value="0">--- Common Breeds----</option>
<option value="Border Collie">Border Collie</option>
<option value="Boxer">Boxer</option>
<option value="Corgi">Corgi</option>
<option value="Dachshund">Dachshund</option>
JS 部分の場合:
breed = document.getElementById("Breed_0_field").value;
selectdog()
function selectdog()
{
dog_type=0
switch (breed)
{
case "Affenpinscher": // Affenpinscher
// Affenpinscher
document.getElementById("dog_breed_picture").src = "http://handicappedpet.net/helppets/images/avatars/gallery/Dog_Larger/blank.gif";
break;
case "Affenpinscher": // Affenpinscher
// Affenpinscher
document.getElementById("dog_breed_picture").src = "http://handicappedpet.net/helppets/images/avatars/gallery/Dog_Larger/Affenpinscher.gif";
break;
case "Afghan Hound": // Afghan Hound
// Afghan Hound
document.getElementById("dog_breed_picture").src = "http://handicappedpet.net/helppets/images/avatars/gallery/Dog_Larger/Afghan_Hound.gif";
break;
問題は、これがすべて数値に対して機能することです。html部分の値は1,2,3,4でした...そして正しい画像は1,2,3,4のケースと一致しました...しかし、htmlの値を名前にする必要があります。それ以外の場合は後でコードの下では、品種名の代わりに番号のみが表示されます。
この画像スイッチを機能させるにはどうすればよいですか?数字ではなく文字列を使用しますか?