ラジオボタン付きのテーブルを作りたいです。
行にカーソルを合わせると、表の行が強調表示されます。('hover' クラスが適用されます) 行の変更をクリックすると、含まれているオプション ボタンがチェックされ、背景色が変更されます ('active' クラスが適用されます)。
アクティブなクラスは、行ではなくラジオが直接クリックされたときにのみ適用されます。また、アクティブなクラスは削除されません。
http://jsfiddle.net/vincentieo/cH7R9/2/
HTML
<form action="paypal-size-guide.html" method="" accept-charset="utf-8">
<table id="sizeOptions">
<thead>File Size</thead>
<tr>
<td><input type="radio" name="size" value="Large" checked="true"> Large</option></td>
<td>3000 x 2000px</td>
<td>£20</td>
</tr>
<tr>
<td><input type="radio" name="size" value="Medium" > Medium</option></td>
<td>1500 x 1000px</td>
<td>£15</td>
</tr>
<tr>
<td><input type="radio" name="size" value="Small" > Small</option></td>
<td>750 x 500px</td>
<td>£10</td>
</tr>
</table>
</form>
JS
$('#sizeOptions tr').click(function() {
$(this).find('td input:radio').prop('checked', true);
});
$('#sizeOptions tr td input:radio').click(function() {
if($(this).is(':checked')) {
$(this).closest('tr').addClass("active");
} else {
$(this).closest('tr').removeClass("active");
}
});
$('#sizeOptions tr').mouseover(function() {
$(this).addClass("hover");
});
$('#sizeOptions tr').mouseout(function() {
$(this).removeClass("hover");
});
CSS
#sizeOptions {
border-collapse: collapse;
padding: 10px;
}
#sizeOptions td {
padding: 10px;
}
#sizeOptions tr {
border-bottom: solid 1px #b1b1b1;
}