<table border="1" align="center" style="width: 500px" id="doctorTable"> <tr> <th>医疗保障人员</th> <th>联系方式</th> <th>操作</th> </tr> <tr > <td><input style="width: 170px" id="name2" name="name" required="required"/></td> <td><input style="width: 170px" id="phone2" name="phone" required="required"/></td> <td><input type="button" value="删除" style="width: 80px" onclick="delDoctorTr(2)" /></td> </tr> </table> //html
<script type="text/javascript"> function addDoctorTr() { var html = "<tr id=‘tr2‘>" +$("#doctorTable tr:eq(1)").html() + "</tr>"; m = doctorTable.rows.length; n = m + 1; html = html.replace(id="name2",id="name"+n); html = html.replace(id="phone2",id="phone"+n); html = html.replace(onclick="delDoctorTr(2)",onclick="delDoctorTr"+"("+n+")"); $("#doctorTable ").append(html); } function delDoctorTr(n) { length = $("#doctorTable tr").length; if (length > 2) { m = n -1; alert($("#doctorTable tr:eq"+"("+m+")").html()); $("#doctorTable tr:eq"+"("+m+")").remove(); } else { jBox.tip("至少保留一行!"); } } </script> //js//doctorTable.rows.length 获取ID为doctorTable的所有的行数//templateTable.rows[0].cells.length 获取ID为templateTable的表格的第一行的有几列//$("#doctorTable tr:eq(1)").html() 第一行的代码
时间: 2024-10-11 04:23:29