-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathhw.html
39 lines (39 loc) · 1.45 KB
/
hw.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<div class="container">
<p id="demo">Click the button to render the table</p>
<button id="click" onclick="myFunction()">Click Me!</button>
<br>
<br>
</div>
<script>
function myFunction() {
const myObj = [
{"user_id": 1, "user_name": "Durga"},
{"user_id": 2, "user_name": "Scott"}
]
text = "<table border='1'>"
text += "<tr><th>Id</th><th>Name</th></tr>"
for (let x in myObj) {
text += "<tr><td>" + myObj[x].user_id + "</td><td>" + myObj[x].user_name + "</td></tr>";
}
text += "</table>"
const tableTag = document.createElement('div')
tableTag.innerHTML = text
document.getElementById("demo").parentNode.appendChild(tableTag)
}
</script>
</body>
</html>