0

好的,所以,我得到了一个列表,当用户从下拉列表中选择一个选项时,我想显示一些文本,我想出了如何为一个选项制作它,但由于某种原因在组中效果不佳。

<select id="mySelect" name="values">
<option value=0>0</option>
<option value=1>1</option>
<option value=2>2</option>
</select>

我打算在选择每个选项时“打印”一些确定的文本,谢谢!

(抱歉有任何语法错误,这里是讲西班牙语的人)

4

1 回答 1

0

设法做到了:

<script type="text/javascript"> 
function showstuff(element){ 
    document.getElementById("una").style.display = element=="una"?"block":"none"; 
    document.getElementById("dos").style.display = element=="dos"?"block":"none"; 
    document.getElementById("tres").style.display = element=="tres"?"block":"none"; 
    document.getElementById("cuatro").style.display = element=="cuatro"?"block":"none"; 
    document.getElementById("cinco").style.display = element=="cinco"?"block":"none"; 
    document.getElementById("seis").style.display = element=="seis"?"block":"none"; 
    document.getElementById("siete").style.display = element=="siete"?"block":"none"; 
    document.getElementById("ocho").style.display = element=="ocho"?"block":"none"; 
    document.getElementById("nueve").style.display = element=="nueve"?"block":"none"; 
    document.getElementById("diez").style.display = element=="diez"?"block":"none";     
    } 
</script> 

<select name="type" onchange="showstuff(this.value);"> 
          <option value="una" selected>1</option> 
          <option value="dos">2</option> 
          <option value="tres">3</option> 
          <option value="cuatro">4</option> 
          <option value="cinco">5</option> 
          <option value="seis">6</option> 
          <option value="siete">7</option> 
          <option value="ocho">8</option> 
          <option value="nueve">9</option> 
         <option value="diez">10</option> 
</select> 
<div id="uno" style="display:none;">uno</div> 
<div id="dos" style="display:none;">dos</div> 
<div id="tres" style="display:none;">tres</div> 
<div id="cuatro" style="display:none;">cuatro</div> 
<div id="cinco" style="display:none;">cinco</div> 
<div id="seis" style="display:none;">seis</div> 
<div id="siete" style="display:none;">siete</div> 
<div id="ocho" style="display:none;">ocho</div> 
<div id="nueve" style="display:none;">nueve</div> 
<div id="diez" style="display:none;">diez</div> 

感谢大家 :)

于 2013-02-26T17:09:52.993 回答