2013-07-19 56 views
0

我想弄清楚爲什麼這個代碼在點擊提交按鈕時不會暴露正確的p標籤。目標是告訴用戶他們的答案是否通過或失敗。jquery某些單選按鈕返回true

$('#screenfail').hide(); 
$('#screensuccess').hide(); 

$('#actiontime').click(function() { 
    if ($("#quest11", "#quest21").is(':checked') == true) { 
     $('#screensuccess').show(); 
    } else { 
     $('#screenfail').show(); 
    } 
}); 

<div> 
    <p>Quest 1.</p> 
    <input type="radio" name="clinic" id="quest11" value="1" />Yes 
    <input type="radio" name="clinic" id="quest12" value="0" />No 

    <p>Quest 2.</p> 
    <input type="radio" name="age" id="quest21" value="1" />Yes 
    <input type="radio" name="age" id="quest22" value="0" />No 

    <p id="screenfail"> 
     Thanks but no thanks. 
    </p> 

    <p id="screensuccess"> 
     You made it! 
    </p> 

    <p> 
     <input id="actiontime" type="submit" value="Submit Me!" name="submit"> 
    </p> 

</div> 

回答

2

更改您的支票:

if ($("#quest11").is(':checked') && $("#quest21").is(':checked')) { 

jsFiddle example

+0

打我,該死! –

+0

同樣...僅僅幾秒鐘 – curtisk

0

另一種方式:

if ($("#quest11:checked, #quest21:checked").length == 2) { 

JSFIDDLE

相關問題