*Create a page: two input boxes and a button
The code is as follows: <html> <head> <title>Dynamically generate table</title> <style type = "text/css"> </style> </head> <body> Line: <input type="text" id="h"/><br/> Column: <input type="text" id="l"/><br/> <input type="button" value="Generate" onclick="add1()"/> <div id="divv"> </div> </body> <script type="text/javascript"> function add1(){ /* 1. Get the input row and column values 2. Generate a table - Loop through rows - Loop through cells in a row 3. Display on the page - Use the innerHTML attribute to set the table code inside a div */ var h =document.getElementById("h").value; //alert(h); var l =document.getElementById("l").value; var tab = "<table border='1' bordercolor='red'>"; for(var i=0;i<h;i++){ tab += "<tr>"; for(var j=0;j<l;j++){ tab +="<td>aaaa</td>" } tab +="</tr>" } tab +="</table>"; var div1 = document.getElementById("divv"); div1.innerHTML = tab; } </script> </html> Effect diagram demonstration: SummarizeThis article ends here. I hope it can be helpful to you. I also hope that you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: Binary Type Operations in MySQL
>>: Docker Gitlab+Jenkins+Harbor builds a persistent platform operation
First, let’s think about a question: To insert su...
How to solve the problem of being unable to acces...
The layout of text has some formatting requiremen...
Table of contents 1. Background 2. Prerequisites ...
When it comes to pictures, the first thing we thi...
Table of contents # Post-data preparation # SQL q...
Using Javascript to implement countdown to close ...
1. Download the RPM package corresponding to Linu...
Table of contents 1. Easy to read code 1. Unified...
1. Installation of the decompressed version (1). ...
Table of contents 1.watch monitors changes in gen...
1. DOCTYPE is indispensable. The browser determin...
In the previous article, we introduced the detail...
Problem description: I bought a Mac and installed...
Summary HTML: element plus v-cloak CSS: [v-cloak]...