123456789101112131415161718192021222324252627282930313233343536 |
- <header>
- <h1>Form</h1>
- </header>
- <body>
- <script>
- obj = {
- "Name": "chevrolet chevelle malibu",
- "Cylinders": 8,
- "Displacement": 307,
- "Horsepower": 130,
- "Weight_in_lbs": 3504,
- "Origin": "USA",
- "in_production": false
- }
- const typesMap = { 'boolean': 'checkbox', 'number': 'number', 'string': 'text' };
- let str = "<form>\n"
- for (var name in obj) {
- value = obj[name];
- type = typeof value;
- htmlType = typesMap[type];
- str += ` <label>${name}: <input type="${htmlType}" value="${value}" /></label>\n`;
- }
- str += "<form>"
- document.write(str)
- alert(str)
- </script>
- </body>
|