jQuery 表格删除,添加行

var colsNum = 4;

1,$(document),ready(function () {

$.("#id1").parent().after('<tr class = "class1"><td style = "dispalay : none">

<input name = "" type ="hidden" value = " '+ nr +' "/>

<input name = "" type ="text" value = " '+ nr +' "/>

<img src="" title = '添加行' onclick = "addItem(this)"/>

<img src="" title = '删除行'  onclick = "delItem(this)"/>

</td></tr>');

//以下代码视情况添加

var sum = $("#title").size():

var colsNum = $("#title").size();

$("#title1").attr("rowspan",sum + 2);

$("#title2").attr("rowspan", sum + 1);

})

2. function addItem(obj){

$.("#id1").parent().parent().after('<tr class = "class1"><td style = "dispalay : none">

<input name = "" type ="hidden" value = " '+ nr +' "/>

<input name = "" type ="text" value = " '+ nr +' "/>

<img src="" title = '添加行' onclick = "addItem(this)"/>

<img src="" title = '删除行'  onclick = "addItem(this)"/>

</td></tr>');

//以下代码视情况添加

var sum = $("#title").size():

var colsNum = $("#title").size();

$("#title1").attr("rowspan",sum + 3);

$("#title2").attr("rowspan", sum + 2);

}

3. function delItem(obj){

var colsNum = colsNum + 1;

var sum = $("#title").size();

if(sum < 2){

alert("当前为最后一行,无法删除!"); return;

$(obj).parent().parent().remove();//删除当前行

$("#title1").attr("rowspan",sum + 1);

$("#title2").attr("rowspan", sum );

}

}

上一篇:团队作业——项目Alpha版本发布


下一篇:centos yum update kernel