html代码:
<div>
<input type="radio" name="rd" class="same" value='选项二' >选项一
<input type="radio" name="rd" class="same" value='选项二'>选项二
<input type="radio" name="rd" class="same others" value='其它'>其它
<input type="text" name="txt" class="txt" value=""/>
</div>
jquery代码:
$(function(){
$(".same").click(function(){
$(this).siblings().attr("checked",false);
$(this).attr("checked",true);
if($(this).attr("class").indexOf('others')>=0){
$(this).siblings('.txt').show();
}
else{
$(".others").siblings('.txt').hide();
}
});
})
注释: if语句也可以使用if($(this).hasClass("others"))进行判断
实现效果如下: