选择单选按钮时如何清除文本字段中的文本 [英] How to clear text inside text field when radio button is select
问题描述
目前我有这个单选按钮
- Eletronics
- 计算机
- 其他
我想要做的是,如果单选按钮其他
被选中,我想显示一个输入文本字段并让用户输入。
我想要做的是,当我选择其他
并在输入字段中输入内容,然后当我选择回到 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
- Eletronics
- Computers
- 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('');
}
});
这篇关于选择单选按钮时如何清除文本字段中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!