【发布时间】:2018-07-20 12:47:09
【问题描述】:
我开发了一个表格,每行有 1 列,每行有一个复选框和 2 个标签。
$('input[type="label"]').click(function() {
var id = $(this).attr("id");
$(this).parent("tr:first").remove()
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<table class="table">
<thead>
<tr>
<th>To Do List</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="checkbox">
<input type="checkbox" id="checkbox1" /><label>Task 1</label><label class="glyphicon glyphicon-trash"></label>
</div>
</td>
</tr>
<tr>
<td>
<div class="checkbox">
<input type="checkbox" id="checkbox2" /><label>Task 2</label><label class="glyphicon glyphicon-trash"></label>
</div>
</td>
</tr>
<tr>
<td>
<div class="checkbox">
<input type="checkbox" id="checkbox3" /><label>Task 3</label><label class="glyphicon glyphicon-trash" id="3"></label>
</div>
</td>
</tr>
</tbody>
</table>
</div>
当我单击删除标签时,应删除整行。并且它下面的行应该自动在上面的一个位置。
在 jquery 中应该做哪些更正?
【问题讨论】:
-
input[type="label"]?对吗? -
而父级不是 tr....
-
还有两个标签在哪里?
-
在每个 div 中有第一个复选框,然后是一个标签“任务 1”,然后是另一个是引导图标(删除图标)。
-
label元素意味着要么有一个for属性指向作为标签的表单元素的id,要么包装表单元素本身。参见例如MDN's documentation。如果你这样做了,那么点击label会自动选中复选框。
标签: javascript jquery html css jquery-ui