【问题标题】:Have Input Box Appear On DropDown Select HTML / Javascript有输入框出现在下拉选择 HTML / Javascript
【发布时间】:2011-06-16 21:50:09
【问题描述】:

嘿,我有一个用 html 完成的下拉框,我只是想知道在选择特定下拉项时是否可以显示 2 个单独的文本框。 所以

下拉菜单 - 项目 1 - 项目 2 - 第 3 项

如果第 3 项被选中,那么

出现输入文本框1-出现输入文本框2

谢谢大家

【问题讨论】:

    标签: javascript html onselect


    【解决方案1】:
    <select id='combo'>
       <option>...</option>
    </select>
    <input  id='text1' style='display: none'/>
    <input  id='text2' style='display: none'/>
    <script>
    // Disclaimer: using a library (jquery, ext-core, prototype) to bind events and change 
    // styles is safer across browsers
    document.getElementById('combo').onchange = function() {
      var display = this.selectedIndex == 2 ? "inline" : "none";
      document.getElementById('text1').style.display = display;
      document.getElementById('text2').style.display = display;
    }
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多