【发布时间】:2010-02-05 23:22:59
【问题描述】:
使用这个作为一个简化的例子,假设我有一个表,其中有一些单选按钮,后跟一个带有链接的 div 元素。然后这种模式会重复一些未知的次数,如下所示:
<table class="rdoBtnList">
<tbody>
<tr>
<td> Person 1 </td>
<td>
<label for="rb1">Verified</label>
<input type="radio" id="rb1" name="rdoBtns" value="Verified" />
<label for="rb2">Not Verified</label>
<input type="radio" id="rb2" name="rdoBtns" value="NotVerified" />
</td>
</tr>
</tbody>
</table>
<div class="PersonLink"><a href="#">Link to Person 1 page</a></div>
..... tables and divs for person 2, 3, ... n, etc
我希望能够使用 jQuery 根据单选按钮的值启用/禁用单选按钮后面的 div 中的链接。我可以获得单选按钮的值,但无法弄清楚我将使用什么选择器语法来启用/禁用 just 单选按钮之后的 div。
到目前为止,这是我的 jQuery:
<script type="text/javascript">
$(document).ready(function() {
$(".rdoBtnList > tbody > tr > td > input").change(function() {
if ($(this).val() == "Verified") {
// select the link in the div following the table and enable it
} else {
// select the link in the div following the table and disable it
}
});
});
</script>
【问题讨论】:
标签: javascript jquery jquery-selectors