【发布时间】:2012-08-29 08:42:24
【问题描述】:
我在 HTML 中的示例:
<table id="testME">
<tr>
<td><input id="first" name="choices" type="radio" value="1"></td>
<td><input id="second" name="choices" type="radio" value="2"></td>
<td><input id="third" name="choices" type="radio" value="3"></td>
</tr>
<tr>
<td><label for="first">My first selection</label></td>
<td><label for="second">My second selection</label></td>
<td><label for="third">My third selection</label></td>
</tr>
<tr>
<td><input id="myWords" type="text" /></td>
<td><select id="mySelects">
<option value="30">Choice 1</option>
<option value="31">Choice 2</option>
</select>
</td>
<td><input id="multiOne" name="multiSelect" type="checkbox" value="one" />
<label for="multiOne">One</label><br />
<input id="multiTwo" name="multiSelect" type="checkbox" value="two" />
<label for="multiTwo">Two</label><br />
<input id="multiThree" name="multiSelect" type="checkbox" value="three" />
<label for="multiThree">Three</label><br />
<input id="multiFour" name="multiSelect" type="checkbox" value="four" />
<label for="multiFour">Four</label><br />
</td>
</tr>
</table>
我希望发生的是,当我单击单选按钮或其标签时,该列中的所有单元格(无论是 th 还是 td)都会以某种颜色突出显示。我想用 JQuery 来做这件事。
在发布这个问题之前我在研究什么:
<script>
function highlightSelection() {
$('#testME > tr > td:nth-child(2)').css('background-color', 'gray');
}
</script>
<input id="jquerytest" type="button" onclick="javascript:highlightSelection();" value="Change Color" />@:
但这似乎不起作用。
【问题讨论】:
-
你试过了吗?也许你可以展示你所做的事情,然后有人可以帮助你实现它?
-
@dotnetN00b 你有没有看过我的回答? :-P
-
@Neal:是的,我是。但我是在回应两张海报。他们肯定有一个合理的观点,当我发布我的问题时,我应该发布我的尝试。
标签: javascript jquery html-table jquery-selectors