【发布时间】:2013-11-19 20:09:27
【问题描述】:
我正在使用 jQuery 1.4。每次选中 "<td>" 内的单选按钮时,我都会尝试突出显示表的 <td> 标记,如果未选中,则删除突出显示类。
这是标记:
CSS: .highlight-blue { 背景色:#81BEF7; }
<table id="tblContainer">
<tr>
<td>
<input type="radio" name="book" value="book1" /> Book 1</td>
<td>
<input type="radio" name="book" value="book2" /> Book 2</td>
<td>
<input type="radio" name="book" value="book3" /> Book 3</td>
<td>
<input type="radio" name="book" value="book4" /> Book 4</td>
</tr>
</table>
Javascript:
// highlight checked radion button
$('#tblContainer :radio').click(function() {
//add class to hilghlight selected radio button
var cell = $(this).closest('td');
if ($(this).is(':checked')) {
cell.addClass('highlight-blue');
}
else {
//remove highlight class
cell.removeClass('highlight-blue');
}
});
问题在于它不会从先前选择的单选按钮中删除该类。
更新 1: 在此处查看新的更新标记http://jsbin.com/egusud/7
【问题讨论】:
标签: javascript jquery jquery-selectors