选择单选按钮时如何清除文本字段中的文本 [英] How to clear text inside text field when radio button is select

查看:153
本文介绍了选择单选按钮时如何清除文本字段中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我有这个单选按钮


  1. Eletronics

  2. 计算机

  3. 其他

我想要做的是,如果单选按钮其他被选中,我想显示一个输入文本字段并让用户输入。



我想要做的是,当我选择其他并在输入字段中输入内容,然后当我选择回到 Eletronics Computers ,我想清除我在输入框中写入的文本。



请向我提供JavaScript或jQuery的解决方案。



这是我的代码示例。请检查它: http://jsfiddle.net/dnGKM/

  $($) ''input:radio')。on('click',function(){
if($(this).attr('id')=='others'){
$('#showhide ').css('opacity',1.0);
} else {
$('#showhide')。css('opacity',0).find('input:text#others_text') .val('');
}
});

< a href =http://jsfiddle.net/dnGKM/8/ =nofollow> DEMO


Currently I have this radio buttons

  1. Eletronics
  2. Computers
  3. Others

What I am trying to do is, if radio button Others is selected, I would like to display an input text field and let the user type.

What I would like to do is, when I select Others and type something inside the input field, then when I choose back to Eletronics or Computers, I would like to clear the text that I wrote inside input field.

Please kindly provide me with the solution of JavaScript or jQuery.

Here is my code sample. Please kindly check it: http://jsfiddle.net/dnGKM/

解决方案

UPDATE

$('input:radio').on('click', function() {
    if($(this).attr('id') == 'others') {
        $('#showhide').css('opacity', 1.0);
   } else {
       $('#showhide').css('opacity', 0).find('input:text#others_text').val('');
    }  
});​

DEMO

这篇关于选择单选按钮时如何清除文本字段中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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