2012-10-10 33 views
0

用戶需要能夠選擇第一個和第二個選擇的時間。我使用單選按鈕......但是如果有更好的東西,我很欣賞輸入。使用單選按鈕(或更好的)確認jQuery的第一個和第二個選擇選擇?

當他們選擇他們的第一選擇時,我想要一個頁面消息說「你選擇了你的第一選擇」,當他們選擇第二選擇時,你想選擇你的第二選擇。

是的,我知道這看起來很簡單......我很新jQuery的...

感謝您的幫助!

HTML:

<table class="tblWorkshop"> 
<tr> 
<td>DAY ONE</td> 
</tr> 
<th>Morning Workshops</th> 
<th></th> 
<th></th> 
<th></th> 
<th>Afternoon Workshops</th> 
<th></th> 
<th></th> 
<tr> 
<td>9:00 am</td><td><input type="radio" name="choice" class="firstChoice" value="0" />First Choice</td><td><input type="radio" name="choice" class="secondChoice" value="1" />Second Choice</td><td class="spotsLeft"></td> 
<td>12:00 pm</td><td><input type="radio" name="choice" class="firstChoice" />First Choice</td><td><input type="radio" name="choice" class="secondChoice" />Second Choice</td><td class="spotsLeft"></td> 
</tr> 
<tr> 
<td>10:30 am</td><td><input type="radio" name="firstChoice" value="0" class="firstChoice" />First Choice</td><td><input type="radio" name="SecondChoice" value="1" class="secondChoice" />Second Choice</td><td class="spotsLeft"></td> 
<td>12:30 pm</td><td><input type="radio" name="firstChoice" value="0" class="firstChoice" />First Choice</td><td><input type="radio" name="SecondChoice" value="1" class="secondChoice" />Second Choice</td><td class="spotsLeft"></td> 
</tr> 
<tr> 
<td>11:00 am</td><td><input type="radio" name="firstChoice" value="0" class="firstChoice" />First Choice</td><td><input type="radio" name="SecondChoice" value="1" class="secondChoice" />Second Choice</td><td class="spotsLeft"></td> 
<td>1:00 pm</td><td><input type="radio" name="firstChoice" value="0" class="firstChoice" />First Choice</td><td><input type="radio" name="SecondChoice" value="1" class="secondChoice" />Second Choice</td><td class="spotsLeft"></td> 
</tr> 
<tr> 
<td>11:30 am</td><td><input type="radio" name="firstChoice" value="0" class="firstChoice" />First Choice</td><td><input type="radio" name="SecondChoice" value="1" class="secondChoice" />Second Choice</td><td class="spotsLeft"></td> 
<td>2:30 pm</td><td><input type="radio" name="firstChoice" value="0" class="firstChoice" />First Choice</td><td><input type="radio" name="SecondChoice" value="1" class="secondChoice" />Second Choice</td><td class="spotsLeft"></td> 
</tr> 
<tr> 
<td>11:45 am</td><td><input type="radio" name="firstChoice" value="0" class="firstChoice" />First Choice</td><td><input type="radio" name="SecondChoice" value="1" class="secondChoice" />Second Choice</td><td class="spotsLeft"></td> 
<td>3:45 pm</td><td><input type="radio" name="firstChoice" value="0" class="firstChoice" />First Choice</td><td><input type="radio" name="SecondChoice" value="1" class="secondChoice" />Second Choice</td><td class="spotsLeft"></td> 
</tr> 
</table> 

SCRIPT:

<script type="text/javascript"> 
var selected =$('input[name=choice]:checked', '.tblWorkshop').val() 

     if (selected == $('input[value=1]:checked', '.tblWorkshop').val()) { 

      alert('First choice selected'); 

     } 

     else if (selected == $('input[value=0]:checked', '.tblWorkshop').val()){ 
      alert('Second choice selected'); 
     } 

}); 

</script> 

回答

相關問題