选择单选按钮时隐藏/显示3个文本框
Hide/display of 3 textboxes on selection of radio button
我有两个单选按钮。在选择一个时,我想显示3个文本框,并在选择另一个时隐藏它。
这是代码。
这是我的两个单选按钮。
<input type="radio" name="type"> Fresher
<input type="radio" name="type"> Experienced
点击有经验的单选按钮后,我想显示这3个文本框。
Company Name: <input type="text" hidden="true"/> <br/>
Designation: <input type="text" hidden="true"/> <br/>
Year_of_Experience: <input type="text" hidden="true"/> <br/>
请帮我用javascript来解决这个问题。
您可以按如下方式执行此操作。首先将您的HTML更改为:
<input type="radio" name="type" value="Fresher"> Fresher
<input type="radio" name="type" value="Experienced"> Experienced
<div id="textboxes" style="display: none">
Company Name: <input type="text" hidden="true"/>
Designation: <input type="text" hidden="true"/>
Year_of_Experience: <input type="text" hidden="true"/>
</div>
此代码为代码添加的内容是为单选按钮设置一个值。这使我们能够根据选择的单选按钮进行选择。其次,在<div>
中将输入字段分组在一起,以便于隐藏三个输入字段。修改HTML后,在您的网站上包含jQuery并使用以下代码:
$(function() {
$('input[name="type"]').on('click', function() {
if ($(this).val() == 'Experienced') {
$('#textboxes').show();
}
else {
$('#textboxes').hide();
}
});
});
您可以使用这个JSFiddle看到这是如何工作的:http://jsfiddle.net/pHsyj/
这是最好的例子。试试这样的东西。,这是的一个例子
$("input[type='radio']").change(function(){
if($(this).val()=="other")
{
$("#otherAnswer").show();
}
else
{
$("#otherAnswer").hide();
}
});
http://jsfiddle.net/Wc2GS/8/
我想这会解决你的问题
<input type="radio" name="type" id='frsradio'> Fresher
<input type="radio" name="type" id='expradio'> Experienced <br>
<input type="text" class='txbx' hidden="true"/> <br/>
<input type="text" class='txbx' hidden="true"/> <br/>
<input type="text" class='txbx' hidden="true"/> <br/>
$(function() {
$('#expradio').click(function() {
$('.txbx').attr('hidden',false);
});
$('#frsradio').click(function() {
$('.txbx').attr('hidden',true);
});
});
工作jsfiddle
请看,您的html元素没有唯一的标识,我只是以通用的方式给出了这段代码。
试试,
$('input[name="type"]:eq(1)').change(function(){
$('input[type="text"]').toggle(this.checked);
});
<input type="radio" name="type" onClick ="radio"> Fresher
<input type="radio" name="type" onClick ="radio"> Experienced
点击有经验的单选按钮,我想显示这3个文本框。
<input type="text" hidden="true" class="text"/> <br/>
<input type="text" hidden="true" class="text"/> <br/>
<input type="text" hidden="true" class="text"/> <br/>
和javascript:-
<script>
function radio()
{
var result = document.getElementsByClassName('text'").style.display="none";
}
</script>
试试这个
<input type="radio" name="type" value="fresher"> Fresher
<input type="radio" name="type" value="exp"> Experienced
<br/>
<input class="box" type="text" hidden="true"/> <br/>
<input class="box" type="text" hidden="true"/> <br/>
<input class="box" type="text" hidden="true"/> <br/>
编写脚本
$("input[type='radio']").on('change',function(){
if($(this).val() == "exp")
$('.box').show('slow');
else
$('.box').hide();
});
演示
试试这个。。。。
<input type="radio" name="type" id="fresh"> Fresher
<input type="radio" name="type" id="exp"> Experienced
<input type="text" class="hid" hidden="true"/> <br/>
<input type="text" class="hid" hidden="true"/> <br/>
<input type="text" class="hid" hidden="true"/> <br/>
$("#fresh").change(function(){
$('.hid').css("style","display:none");
});
$("#exp").change(function(){
$('.hid').css("style","display:block");
});
For default hide the text boxes In OnRender Complete Method you need hide the three textbox for that you put the below code.
$("#textbox 1").hide();
$("#textbox 2").hide();
$("#textbox 3").hide();
你需要把代码写在零钱上的单选按钮上。
Using the Id get the value of radio button
var val=$('#radioId').val;
if(val=='Fresher')
{
$("#textbox 1").show();
$("#textbox 2").show();
$("#textbox 3").show();
}
else if (val=='Experienced'){
$("#textbox 1").hide();
$("#textbox 2").hide();
$("#textbox 3").hide();
}
相关文章:
- onkeyup无法动态创建多个文本区域
- 借助asp.net验证或java脚本对多个文本进行验证
- 将循环中的两个文本框相乘,并在第三个文本框上显示结果
- 使用加号按钮添加多个文本框,并通过PHP提交
- 使用javascript将两个文本框值相加到表中的另一个文本框中
- jQuery自动完成功能不适用于多个文本输入
- 根据用户从下拉列表中的选择显示多个文本框
- 如何使用jQuery对多个文本区域进行字数统计
- 单击按钮显示不同的文本,重复第一个文本
- 插入多个文本分隔符-javascript
- 使用敲除绑定多个文本数据
- 同时在两个文本框上显示光标
- javascript:无法添加两个文本输入
- 识别两个文本中的单词(if 语句在 for 循环中)
- j查询在多个文本框之间指定
- 如何使用HTML5和Javascript同时读取两个文本文件
- 更改多个文本框并选择从一行检索到另一行的数据
- jQuery UI日期选择器只响应第一个文本框
- 创建选项卡,每个选项卡有两个文本区域
- Ajax-为php填充多个文本框