当单元格内的单选按钮被单击时,我想要更改表格单元格的背景颜色。
<table>
<tr>
<td align="center">
<input type="radio" value="foo"
onclick="this.parentElement.style.background-color='red';" />
</td>
</tr>
</table>
如何获取父元素引用?
发布于 2010-03-16 20:41:41
使用纯javascript:
element.parentNode
在jQuery中:
element.parent()
发布于 2010-03-16 20:43:36
使用select的change事件:
$('#my_select').change(function()
{
$(this).parents('td').css('background', '#000000');
});
https://stackoverflow.com/questions/2454308
复制相似问题