[英]jquery radio button show / hide
我有3个单选按钮。
*如果单击“电子邮件”按钮,则只会显示电子邮件文本框
*如果单击集合,将仅显示集合文本框并隐藏其他div。 我怎么做? 以下代码似乎仅显示但更改后不隐藏!
<input type="radio" name="d_method" class="c_email"/>Email
<input name="d_method" type="radio" class="c_collection"/>Colletion
<input name="d_method" type="radio" class="c_post"/>Post
和3个具有ID的隐藏div:
<div id="c_email" style="display:none;">
email textbox
</div>
<div id="c_collection" style="display:none;">
collection textbox
</div>
<div id="c_post" style="display:none;">
post textbox
</div>
和jQuery的:
$('.c_email').change(function() {
$('#c_email').stop().fadeIn();
}, function(){
$('#c_email').stop().hide();
})
$('.c_collection').change(function() {
$('#c_collection').stop().fadeIn();
}, function(){
$('#c_collection').stop().hide();
})
$('.c_post').change(function() {
$('#c_post').stop().fadeIn();
}, function(){
$('#c_post').stop().hide();
})
你可以做
$(':radio').change(function() {
var itemSelector = '#' + $(this).attr('class');
$('div').stop().fadeOut(function() {
$(itemSelector).fadeIn();
});
});
这都是基于您的约定,即类名与您的ID <div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.