【发布时间】:2019-10-01 22:28:12
【问题描述】:
我试图在 HTML 中创建一个删除按钮来删除数组中的一个元素,但为什么它不起作用? https://github.com/Clifford026/TodoList
<script>
function rem(value){
todolist.splice(i,0);
}
</script>
.
.
.
<% for(var i=0; i <todolist.length; i++){ %>
<lt> <%= todolist[i].name %></lt>
<button onclick = "rem(i)">x</button><br>
<% } %>
【问题讨论】:
-
将 todolist.splice(i,0) 更改为 todolist.splice(i,1)。快速查看一下您的 sn-p,您应该就在这之后。
标签: javascript html ejs