需要准备的材料分别有:电脑、html编辑器、浏览器。
1、首先,打开html编辑器,新建html文件,例如:index.html,编写基础代码。
2、在index.html中的<script>标签,输入js代码:$('table tr').eq(1).remove()$('table tr').eq(1).remove()。
3、浏览器运行index.html页面,此时发现表格的最后2行都被js删除了。
用 splice ( Array.prototype.splice ) 方法。splice 方法修改数组内容,删除对应项,添加新的项。
array.splice( start )// 从第 start 项开始删除后面所有项
array.splice( start, deleteCount )// 从第start项开始,删除后面deleteCount 数量的项
array.splice( start, deleteCount, item1, item2 ... )// 从第start项开始,删除后面deleteCount数量的向,并用 item1, item2 ... 替换。
对于你的需求,例子如下:
var arr = [ 0, 1, 2, 3, 4, 5, 6 ]arr.splice( 3, 1 ) // 删除数组第三项
console.log( arr ) // output [ 0, 1, 2, 4, 5, 6 ]