如何用js删除表格一行或者多行

JavaScript08

如何用js删除表格一行或者多行,第1张

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

<!DOCTYPE html>

<html lang="">

<head>

<meta charset="gb2312">

<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">

<title>123</title>

<script src="Scripts/jquery.min.js" type="text/javascript"></script>

<script type="text/javascript">

$(document).ready(function(){

var spotMax = 30

if($('div.spot').size() >= spotMax) {$(obj).hide()}

$("input#add").click(function(){     addSpot(this, spotMax)

})

})

function addSpot(obj, sm) {

$('div#spots').append(

'<div>' +

'<span><input name="shengfen" type="text" /></span>'+

'<span><input name="diqu" type="text" /></span>'+

'<input type="button" class="remove spot01" value="删除行" /></div>')

.find("input.remove").click(function(){

$(this).parent().remove()

$('input#add').show()

})

if($('div.spot').size() >= sm) {$(obj).hide()}

}

</script>

</head>

<body>

<span><input name="shengfen" type="text" /></span>

<span><input name="diqu" type="text" /></span>

<input type="submit" id="add" name="Submit" value="添加行" >

<div>

<form method="post" name="asdf" id="asdf"><div id="spots"></div></form>

</div>

</body>

</html>

效果这样(样式再自己调)

要加jQuery插件进去

不懂再追问