//添加行
function table_jl_Workhours_Add()
{
var $tr = $("#tr_Workhours").clone(); //增加一行,克隆第一个对象
$("#table_jl_Workhours").append($tr);
@*var $tr = $("<tr style='text-align:center'>" + "<td>填报人:<span>@ViewBag.Operator</span></td>" + "<td style='width:15%' > 设备:<select name= 'equipName' id= 'equipName' style= 'width:100px' οnmοusedοwn=\"table_jl_Workhours_SelectEquip()\" ></select ></td>" + "<td style='width:30%'> 零件数量:<span style= 'color:red;'>(请输入数字!)</span >"+ "<input type= 'text' name= 'PartsAmount' id= 'PartsAmount' style= 'width:50px' /></td > " + "<td style='width:30%'> 耗时:<span style= 'color:red;' >(请输入数字!)</span >" + "<input type= 'text' name= 'Workhours' id= 'Workhours' style= 'width:50px' /></td > " + "<td style='width:10%'><button id='Add' οnclick='return table_jl_Workhours_Add()'>增行</button>"+ "<button id= 'delete' οnclick= \"return table_jl_Workhours_Del('btn',this)\"> 删行</button ></td>" + "</tr>");
var lastIndex = $('#table_jl_Workhours:first tbody tr').length - 2;
var lastRow = $('#table_jl_Workhours:first tbody tr:eq(' + lastIndex + ')'); lastRow.after($tr);*@
//得到倒数第二行
var lastIndex = $('#table_jl_Workhours:first tbody tr').length - 2;
$('#table_jl_Workhours:first tbody tr:eq(' + lastIndex + ')').find(":input").val('');
//$("#table_jl_Workhours tbody tr:last").find(":input").val(''); //将尾行元素克隆来的保存的值清空
return false;
}
删除行
//删除一行 function table_jl_Workhours_Del(tableID,obj)
{
//$("#table_jl_Workhours tr:not(:first):not(:first):last").remove();//移除最后一行,并且保留前一行
//var table = document.getElementById("table_jl_Workhours"),
// trs = table.getElementById("tr_Workhours")
//for (var i = trs.length - 1; i > 0; i--) {
// table.deleteRow(i);
//} // $("#table_jl_Workhours #tr_Workhours").not('#tr_Workhours:first').remove();
//let btnlist = document.querySelectorAll('.delete');
// for(let i = 0;i<btnlist.length;i++){
// btnlist[i].onclick = function () {
// this.parentNode.parentNode.remove();
// }
// }
var rowIndex = obj.parentElement.parentElement.rowIndex;
var count = $("#table_jl_Workhours tr").length; if (count> 4)
{
obj.parentElement.parentElement.parentElement.deleteRow(rowIndex);
}
return false;
}