有時(shí)候會遇到這么一個(gè)很簡單的功能:
jquery實(shí)現(xiàn)點(diǎn)擊radio,當(dāng)選中‘其它’時(shí),顯示后面輸入框;否則隱藏
html代碼:
<div> <input type="radio" name="rd" class="same" value='選項(xiàng)二' >選項(xiàng)一 <input type="radio" name="rd" class="same" value='選項(xiàng)二'>選項(xiàng)二 <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"))進(jìn)行判斷。

如果你有更好的解決辦法請留言交流,謝謝!
看了網(wǎng)友的回復(fù),CSS其實(shí)是最簡單的:
.others ~ input[type='text'] {    display:none;}.others:checked ~ input[type='text'] {    display:inline;}注:但是但是IE9以下低版本不支持。
新聞熱點(diǎn)
疑難解答