我试图根据单选按钮的选择切换内容DIV。
单选按钮的HTML。
<div class="row-fluid">
<label class="radio">
<input type="radio" name="account" id="yes" value="yes" checked>
Yes, I have an existing account
</label>
<label class="radio">
<input type="radio" name="account" id="no" value="no">
No, I don't have an account
</label>
</div>
内容DIV
<div id="account_contents">
<p>This is account contents.......</p>
</div>
这就是我在jquery中尝试过的方法。
$('#no').bind('change',function(){
$('#account_contents').fadeToggle(!$(this).is(':checked'));
$('#account_contents').find("input").val("");
$('#account_contents').find('select option:first').prop('selected',true);
});
但这对我来说不正确。在这里,我只想在用户没有帐户的情况下显示此内容DIV。
谁能告诉我如何解决这个问题?
似乎您需要.on('change')单选按钮,而不仅仅是其中一个
$('input[type="radio"][name="account"]').on('change',function(){
var ThisIt = $(this);
if(ThisIt.val() == "yes"){
// when user select yes
$('#account_contents').fadeOut();
}else{
// when user select no
$('#account_contents').fadeIn();
$('#account_contents').find("input").val("");
$('#account_contents').find('select option:first').prop('selected',true);
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句