1
我無法獲得所選的<option>
值。 <select>
s是從數據庫動態形成表格行。所有<select>
都具有相同的類名。從特定選擇中獲取選定的選項值
這裏是我的HTML:
<tr>
<td class="std_code">2014-1-10</td>
<td>Student 10</td>
<td>66</td>
<td>100</td>
<td>66</td>
<td>
<select class="degree_accept_id">
<option value="1">BA(LAW)</option>
<option value="2">BE(EE)</option>
</select>
</td>
<td>17 November 2014</td>
<td>
<a href="" class="ee_accept_suggestion"><i class="fa fa-check fa-lg"></i></a>
</td>
</tr>
<tr>
<td class="std_code">2014-1-9</td>
<td>Student 9</td>
<td>69</td>
<td>100</td>
<td>69</td>
<td>
<select class="degree_accept_id">
<option value="1">BA(LAW)</option>
<option value="2">BE(EE)</option>
</select>
</td>
<td>17 November 2014</td>
<td>
<a href="" class="ee_accept_suggestion"><i class="fa fa-check fa-lg"></i></a>
</td>
</tr>
<tr>
<td class="std_code">2014-1-8</td>
<td>Student 8</td>
<td>71</td>
<td>100</td>
<td>71</td>
<td>
<select class="degree_accept_id">
<option value="1">BA(LAW)</option>
<option value="2">BE(EE)</option>
<option value="3">BE(ME)</option>
</select>
</td>
<td>17 November 2014</td>
<td>
<a href="" class="ee_accept_suggestion"><i class="fa fa-check fa-lg"></i></a>
</td>
</tr>
JS代碼:
<script>
$(document).ready(function() {
$('.ee_accept_suggestion').click(function(e) {
e.preventDefault();
var std_code = $(this).parent().siblings(".std_code").text();
//var selected_degree = $(".degree_accept_id option:selected", this).attr("value");
//var selected_degree = $(this).val();
var selected_degree = $("select.degree_accept_id").val();
alert(selected_degree);
});
});
</script>
問題:alert
總是顯示。
這實際上工作!但是,$(this).closest('tr')背後的邏輯是什麼?find('。degree_accept_id')。val(); – Shariati
@Shariati - 查看編輯的解釋:) –
Thanks @ Travis J – Shariati