Javascript组合框
我有一个组合框,它给了我3个选项,当你转到该选项时,if会在选项框外给我一个图像。我想做的是能够显示html而不是图像Javascript组合框,javascript,html,combobox,Javascript,Html,Combobox,我有一个组合框,它给了我3个选项,当你转到该选项时,if会在选项框外给我一个图像。我想做的是能够显示html而不是图像 function display_map(mapid) { println(mapid); if (mapid == "ireland_map") { document.getElementById('ireland_map').style.display = "block"; document.getElementById('a
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>
功能显示图(mapid){
println(mapid);
如果(mapid==“爱尔兰地图”){
document.getElementById('ireland_map').style.display=“block”;
document.getElementById('africa_map').style.display=“无”;
document.getElementById('america_map').style.display=“无”;
}
else if(mapid==“非洲地图”){
document.getElementById('ireland_map').style.display=“无”;
document.getElementById('africa_map').style.display=“block”;
document.getElementById('america_map').style.display=“无”;
}else if(mapid==“美国地图”){
document.getElementById('ireland_map').style.display=“无”;
document.getElementById('africa_map').style.display=“无”;
document.getElementById('america_map').style.display=“block”;
}
否则{
document.getElementById('ireland_map').style.display=“无”;
document.getElementById('africa_map').style.display=“无”;
document.getElementById('america_map').style.display=“无”;
}
}
爱尔兰
非洲
美国
嘿,1号有效
嘿,2个有用
嘿,3个有用
您的div和选项上都有相同的id。这就是它不起作用的原因
问题是什么?请明确说明please.println不是javascript函数是的,我也让它在fiddle中工作,但当我将代码应用到wordpress时,它突然停止工作:/