如何使用jQuery根据选择值隐藏和显示文本框 [英] how to hide and show text box according to select value using jquery

查看:325
本文介绍了如何使用jQuery根据选择值隐藏和显示文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据下拉选择值隐藏并显示我的文本框.如果用户选择下拉值"other",那么我想显示我的文本框并隐藏下拉列表,他可以选择任何值,除了其他我的文本框是hide plz help me并给我示例代码,我的代码在这里

i want to hide and show my text box according to drop down select value. if user select drop down value "other" then i want show my text box and hide drop down list and he can select any value except other my text box is hide plz help me and give me sample code my code is here

 <script type="text/javascript">
  $( function () {

 if($("#subject").val()==="Other") {
     $("#Sub").show();
  $("#subject").hide();

  }
  else $("#Sub").hide(); 
    });

  <tr> <td style="width: 470px"><%:Html.DropDownList("subject",ViewData["sub"] as SelectList) %> 

      <input type ="text"  name="subject" id="Sub"style="width: 250px" /></td></tr>

我从数据库中填充了下拉列表

i populated drop down list from data base

推荐答案

为此,您必须在select的"change"事件上附加一个事件(并首先隐藏输入的文本).试试这个:

To do this you must attach an event on "change" event of the select (and hide the text input first). try this:

$("#Sub").hide();
$("#subject").change(function(){
    if ($(this).val() === "Other"){
        $("#Sub").show(); 
        $("#subject").hide();
    }else{
        $("#Sub").hide();
    }
});

这篇关于如何使用jQuery根据选择值隐藏和显示文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆