0

我有一个组合框,它给了我 3 个选项,当你转到选项时,如果给我一个选项框之外的图像。我想要做的是能够显示 html 而不是图像。

function display_map(mapid) {
    println(mapid);
    if (mapid == "ireland_map") {
        document.getElementById('ireland_map').style.display = "block";
        document.getElementById('africa_map').style.display = "none";
        document.getElementById('america_map').style.display = "none";
    }
    else if (mapid == "africa_map") {
        document.getElementById('ireland_map').style.display = "none";
        document.getElementById('africa_map').style.display = "block";
        document.getElementById('america_map').style.display = "none";
    } else if (mapid == "america_map") {
        document.getElementById('ireland_map').style.display = "none";
        document.getElementById('africa_map').style.display = "none";
        document.getElementById('america_map').style.display = "block";
    }
    else {
        document.getElementById('ireland_map').style.display = "none";
        document.getElementById('africa_map').style.display = "none";
        document.getElementById('america_map').style.display = "none";
    }
}​

<select name="#" id="map_select" onChange="display_map('freddy');">
      <option selected="selected"></option>
      <option id="ireland_map">ireland</option>
      <option id="africa_map">africa</option>
      <option id="america_map">america</option>
</select>

<div id="ireland_map" style="display:none;"> hey, 1 works </div>
<div id="africa_map" style="display:none;"> hey, 2 works </div>
<div id="america_map" style="display:none;"> hey, 3 works </div>​
4

1 回答 1

1

您的 div 和选项具有相同的 ID。这就是它不起作用的原因。

http://jsfiddle.net/jbabey/z9Jct/

于 2012-05-18T15:42:39.070 回答