启用单个复选框



我试图实现的目标:一旦我单击一个文档(即文档1),我希望启用该文档右侧的框,以便用户可以选中它。但是,它当前已设置,因此如果用户单击文档1,所有框都将启用。

我只是以文档1为例,但我希望每个文档链接都有这个。有人能帮忙吗?

我做了一些研究,但找不到任何具体的解决方案。

我当前的代码:

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td
{
border:1px solid black;
border-collapse:collapse;
}
</style>
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
    $("a").click(function() {
        $("input").removeAttr("disabled");
    });
});
</script>
</head>
<body>
<form method="post" action="mailto:@null">
<table style="width:500px">
<tr>
    <td><a href="https://null" target="_d1">Document 1</a>
    <td><input type="checkbox" name="name1" value="D1" disabled></td>
    </tr>
<tr>
    <td><a href="https://null" target="_d2">Document 2</a></td>
    <td><input type="checkbox" name="name1" value="D2" disabled></td>
    </tr>
<tr>
    <td><a href="https://null" target="_d3">Document 3</a></td>
    <td><input type="checkbox" name="name1" value="D3" disabled></td>
    </tr>
<tr>
    <td><a href="https://null" target="_d4">Document 4</a></td>
    <td><input type="checkbox" name="name1" value="D4" disabled></td>
    </tr>
<tr>
    <td><a href="https://null" target="_d5">Document 5</a></td>
    <td><input type="checkbox" name="name1" value="D5" disabled></td>
    </tr>
<tr>
    <td><a href="https://null" target="_d6">Document 6</a></td>
    <td><input type="checkbox" name="policyAcknowledgement" value="D6" disabled></td>
    </tr>
</table>
<input type="submit">
<input type="reset">
</form>
</script>
</body>
</html>

将jQuery更改为:

$("a").click(function (e) {
    e.preventDefault();
    $(this).parent().next().find('input').removeAttr("disabled");
});

jsFiddle示例

最新更新