Dropdownlist Onchange显示其他下拉列表

时间:2013-09-05 11:58:19

标签: javascript html

我的问题是我想用javascript创建一个类别选择系统但是当我选择一个选项时它会显示所有的div;它应该只显示一个div。

例如:if value = emlak然后show div id=emlak


JS

function getData(dropdown) {
 var value = dropdown.options[dropdown.selectedIndex].value;
 if (value = 'emlak'){
  document.getElementById("emlak").style.display = "block";
 }
 if(value = 'vasita'){
  document.getElementById("vasita").style.display = "block";
 }
}

HTML

<select name="kategori" onChange="getData(this);">
     <option value="hat" onClick="">Hat</option>
     <option value="emlak">Shirt</option>
     <option value="vasita">Pants</option>
</select>
<select id="emlak" name="currentList" onChange=";" style="display:none;">
     <option value="hat">Hat</option>
     <option value="emlak">Shirt</option>
     <option value="pants">Pants</option>
</select>
<select id="vasita" name="currentList" onChange="" style="display:none;">
     <option value="hat">Otomobil</option>
     <option value="emlak">Shirt</option>
     <option value="pants">Pants</option>
</select>

1 个答案:

答案 0 :(得分:3)

试试这个问题,您的问题处于if状态,您没有使用==

function getData(dropdown) {
  var value = dropdown.options[dropdown.selectedIndex].value;
 if (value == 'emlak'){
  document.getElementById("emlak").style.display = "block";
  document.getElementById("vasita").style.display = "none";
 }
 if(value == 'vasita'){
   document.getElementById("vasita").style.display = "block";
   document.getElementById("emlak").style.display = "none";
 }
}

Demo

Update Demo