需求:js 使用deleteRow()同时删除rowIndex 为4和5的行

JavaScript018

需求:js 使用deleteRow()同时删除rowIndex 为4和5的行,第1张

<!DOCTYPE HTML>

<html lang="en-US">

<head>

<meta charset="UTF-8">

<title>main.html</title>

<script type="text/javascript">

function init ()

    {

    var table = document.getElementById ('table')

    table.deleteRow(4)

    table.deleteRow(4)

    }

</script>

</head>

<body>

<button onclick="init()">deleteRow</button>

<table id="table">

<tr>

<td>0</td>

</tr>

<tr>

<td>1</td>

</tr>

<tr>

<td>2</td>

</tr>

<tr>

<td>3</td>

</tr>

<tr>

<td>4</td>

</tr>

<tr>

<td>5</td>

</tr>

<tr>

<td>6</td>

</tr>

<tr>

<td>7</td>

</tr>

</table>

</body>

</html>

需要准备的材料分别有:电脑、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删除了。