- <!DOCTYPE html>
- <html lang="en-US">
- <head>
- <meta charset="UTF-8">
- <title>无限增加行编辑</title>
- <script src1="jquery.js" type="text/javascript"></script>
- <script type="text/javascript">
- var RowsNum = 0;
- function _addRows()
- {
- RowsNum += 1;
- var newIdAndName = "text" + RowsNum;
- var html = "<p id='"+newIdAndName+"'><input type='text' name='" + newIdAndName + "' /><input type='button' value='删除行' onclick=\\"_delBtn();\\" /></p>";
- var strHrml = $(".editPaenl div").html();
- $(".editPaenl div").html(strHrml + html);
- }
- function _delBtn()
- {
- RowsNum = $(".editPaenl div").children().length;
- var MaxpId = "#text" + RowsNum;
- $(MaxpId).remove();
- if(RowsNum == 1) RowsNum = 0;
- }
- </script>
- </head>
- <body>
- <div class="editPaenl">
- <input type="text" name="text1" /><input type="button" id="AddBtn" value="增加行" onclick="_addRows();" />
- <div>
- </div>
- </div>
- </body>
- </html>
- //该片段来自于http://www.codesnippet.cn/detail/110220148671.html
来源: http://www.codesnippet.cn/detail/110220148671.html