hw07_17.html 785 B

123456789101112131415161718192021222324252627282930313233343536
  1. <header>
  2. <h1>Form</h1>
  3. </header>
  4. <body>
  5. <script>
  6. obj = {
  7. "Name": "chevrolet chevelle malibu",
  8. "Cylinders": 8,
  9. "Displacement": 307,
  10. "Horsepower": 130,
  11. "Weight_in_lbs": 3504,
  12. "Origin": "USA",
  13. "in_production": false
  14. }
  15. const typesMap = { 'boolean': 'checkbox', 'number': 'number', 'string': 'text' };
  16. let str = "<form>\n"
  17. for (var name in obj) {
  18. value = obj[name];
  19. type = typeof value;
  20. htmlType = typesMap[type];
  21. str += ` <label>${name}: <input type="${htmlType}" value="${value}" /></label>\n`;
  22. }
  23. str += "<form>"
  24. document.write(str)
  25. alert(str)
  26. </script>
  27. </body>