我正在尝试删除已选中复选框的表行。这是我可以向表中添加行的代码,但我不知道如何仅删除选中的行。
$( document ).ready(function() {
$("#add").on("click",function(){
$('table').append('<tr> <td><input type="checkbox" name="vehicle" value="Bike"></td><td>Color Option : <input type="color" name="favcolor"></td><td>Item ID: <input type="text" name="firstname"></td> </tr>');
});
});
Run Code Online (Sandbox Code Playgroud)
你能看看这个演示,让我知道如何只删除选中的行
删除按钮的 ID 中有一个尾随空格删除它
<button id="remove" type="button">Reomve Selected Color</button>
Run Code Online (Sandbox Code Playgroud)
然后添加一个点击处理程序并使用.has()查找带有选中复选框的行
$("#remove").on("click", function () {
$('table tr').has('input[name="vehicle"]:checked').remove()
})
Run Code Online (Sandbox Code Playgroud)
演示:小提琴