javascript – jQuery在选择选项时显示文本框

前端之家收集整理的这篇文章主要介绍了javascript – jQuery在选择选项时显示文本框前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有以下代码
  1. <select>
  2. <option value="Type 1">Type 1</option>
  3. <option value="Type 2">Type 2</option>
  4. <option value="Type 3">Type 3</option>
  5. <option value="Other">Other</option>
  6. </select>
  7.  
  8. <input type="text" id="other" />

我想要做的是使用jQuery默认隐藏下面的文本框,然后在用户从下拉列表中选择其他选项时显示它.

解决方法

这里不需要任何CSS.
  1. $('#sel').change(function() {
  2. var selected = $(this).val();
  3. if(selected == 'Other'){
  4. $('#other').show();
  5. }
  6. else{
  7. $('#other').hide();
  8. }
  9. });

猜你在找的jQuery相关文章