Home >Web Front-end >JS Tutorial >A small example of jquery dynamically adding and deleting table rows_jquery

A small example of jquery dynamically adding and deleting table rows_jquery

WBOY
WBOYOriginal
2016-05-16 17:15:171010browse

Copy code The code is as follows:



< /head>

<script><br> $(function(){<br> var show_count = 20; //The number of items to be displayed<br> var count = $(" input:text").val(); //The starting value of the increment, here is your ID<br> var fin_count = parseInt(count) (show_count-1); //The conditions for ending the increment<br> <p> $("#btn_addtr").click(function(){<br> if(count < fin_count) //When clicking, if the current number is less than the condition for the end of increment <br> {<br> $( "tr:eq(1)").clone().appendTo("table"); //Add a row after the table<br> $("tr:last td input:first").val( count); / /Change the ID value of the added row <br> }<br> });<br> });</p> <p> function deltr(){<br> var length=$("tr").length;<br> if(length<=2){<br> alert("Keep at least one line");<br> } else{<br> $("tr:last").remove();<br> }<br> }<br></script>












IDUsername  UsertypeOther




Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn