我有一个 2012 年和 2013 年的日期选择器。根据选择,我只想显示某些类的行。有人可以告诉我哪里出错了吗?
jQuery
<script>
$(document).ready(function() {
$(".yr12 td").hide();
$('#selectYr').change(function () {
var val = $(this).val();
if (val == yr12) {
$('.yr12 td').show();
$('.yr13 td').hide();
} else {
$('.yr12 td').hide();
$('.yr13 td').show();
}
});
});
html
<select id="selectYr">
<option value="yr13">2013</option>
<option value="yr12">2012</option>
</select>
<br><br>
<table>
<tr>
<th>Date</th>
<th>Description</th>
</tr>
<tr class="yr13">
<td>February 2013 </td>
<td>Description 1</td>
</tr>
<tr>
<td class="yr13">January 2013</td>
<td>Description 2</td>
</tr>
<tr class="yr12">
<td>November 2012</td>
<td>Description 3</td>
</tr>
<tr class="yr12">
<td>December 2012</td>
<td>Description 4</td>
</tr>
</table>