jQuery下拉菜单中的“显示输入字段”选项

jQuery下拉菜单中的“显示输入字段”选项,jquery,select,input,Jquery,Select,Input,jQuery获取值问题。 选择选项值other时,如何获取输入字段 <script src="//code.jquery.com/jquery-1.11.3.min.js"></script> <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script> <select id="carm3" name="interest"> <option

jQuery获取值问题。 选择选项值other时,如何获取输入字段

 <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
 <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>


 <select  id="carm3" name="interest">
 <option value="">    Dogs</option>
 <option value="">    Cats</option>
 <option value="">    Rabbits</option>
  <option  value="    other">other</option>
  </select>
 <input type="text" name="other_interest" style="display:none" />

<script>
      jQuery(document).ready(function() {
          jQuery("#carm3").val(3).text(function() {
          if (jQuery.inArray(jQuery("other"))){ 
           jQuery('input[name=other_interest]').show();   
              return false;
          } 
        });

  });

狗
猫
兔子
其他
jQuery(文档).ready(函数(){
jQuery(“#carm3”).val(3).text(函数(){
if(jQuery.inArray(jQuery(“其他”)){
jQuery('input[name=other_interest]')。show();
返回false;
} 
});
});
给你:

jQuery(文档).ready(函数(){
jQuery(“#carm3”).change(函数(){
if(jQuery(this).val()='other'){
jQuery('input[name=other_interest]')。show();
}否则{
jQuery('input[name=other_interest]')。hide();
}
});
});

狗
猫
兔子
其他

像这样-请注意,我删除了值中的前导空格并处理重新加载

$(函数(){
$(“#carm3”)。关于(“更改”,函数(){
$('input[name=“other_interest”]”)。切换(this.value==“other”);
}).change();//重新加载时
});

狗
猫
兔子
其他

欢迎来到SO。也请看一看