javascript - 如何在 js 中使用 SHIFT() 方法?
问题描述
我尝试使用 shift() 方法删除第一个元素。但它没有用。如何使用来更正此功能?
`// id="delete-first" in HTML
// the element into the array displayed in HTML
// I want to delete the first element
$("#delete-first").click(function(){
$("#list-student").shift(); // I have issue this line
// $("list-student").first().remove(); // this code is not working too.
});`
Please, fix it to help me.
Sincerely.
解决方案
您正在尝试删除该#list-student
项目的第一次出现 - 只需选择它并使用remove
:
$("#list-student").remove();
您不需要选择第一个元素,因为 ID 是唯一的。
推荐阅读
- r - 如何使用 gsub 从字符串中删除字符,但有例外
- spring-boot - 使用 Gradle 的 Spring Boot 项目中的自定义属性
- python - 从 3D DICOM 图像重建 2D X 射线
- r - 返回与字符串向量关联的值向量?
- java - 如何在 lambda 函数中延迟初始化 Map?
- android - 存储访问框架:查询用户选择的文件夹 uri 时出现不支持的 Uri 错误
- c# - 防止 IHttpClientFactory 为处理程序创建 DI 范围
- .net - 哪个控制 TabIndex 的“重新启动”编号?
- manim - 如何在两种颜色之间闪烁mobject
- python - 使用 numpy 转置列表列表,以便可以将其上传到 gsheet