如果选中单选按钮,则显示文本框Jquery [英] If radio button is check display a textbox Jquery

查看:615
本文介绍了如果选中单选按钮,则显示文本框Jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我的单选按钮有一个问题,我有这3个按钮

Hey Ya'll I have got a question with my radio buttons I have these 3 buttons

No <input type="radio" name="answer" checked="checked" value="no"/> 
Yes<input type="radio" name="answer" value="yes"/> 
Other <input type="radio" name="answer" value="other"/>

我也有这个文本框

<input style="display:none;" type="text" name="otherAnswer" id="otherAnswer"/>

如果用户选择值为"other"的单选按钮,则显示该文本框,如果其他任何操作均不显示该文本框.

if the user selects the radio button with the value of "other" then display the textbox, if its anything else dont display the textbox.

我对Jquery还是很陌生,我已经为此查询了语法,但是对我来说却很希腊.如果有人能指出我正确的方向,那就太好了!

I am fairly new to Jquery and I have looked up syntax for this but its all greek to me. If anyone can point me in the right direction that would be awesome!

推荐答案

$("input[type='radio']").change(function(){

   if($(this).val()=="other")
   {
      $("#otherAnswer").show();
   }
   else
   {
       $("#otherAnswer").hide(); 
   }

});

这是工作示例: http://jsfiddle.net/Wc2GS/8/

这篇关于如果选中单选按钮,则显示文本框Jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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