我做了下面的例子来说明我的问题:定语工作不正常
$("tr > td > #arm").on("click", function() {
$(this).parent().children("#arm").prop("disabled", true);
$(this).parent().children("#disarm").prop("disabled", false);
});
$("tr > td > #disarm").on("click", function() {
$(this).parent().children("#arm").prop("disabled", false);
$(this).parent().children("#disarm").prop("disabled", true);;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<table>
<tr>
<td>
<button id="arm" disabled>Arm</button>
</td>
<td>
<button id="disarm">Disarm</button>
</td>
</tr>
</table>
<script>
</script>
我有以上table
使用包含2 cells
一个row
并在每个cell
一个button
。其中之一是disabled
所以我做了一个脚本,当我按下第二个button
它应该启用第一个并禁用被点击的脚本。
禁用被点击的button
正如我所料,但我不知道为什么它不启用其他button
。
'id'必须在整个页面是唯一的。如果你的真实代码中有多行,这将是一个问题。改用'class'或'name'。 –
元素'id's必须是唯一的,所以当你使用它们时,不需要使用遍历函数。尝试直接选择它们。 –
如果你点击按钮,你为什么选择它的父母,并重新选择你刚才点击的按钮? – epascarello