bluebelt.html 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. var someTree = {
  11. tagName: "table", //html tag
  12. subTags: [ //вложенные тэги
  13. {
  14. tagName: "tr",
  15. subTags: [
  16. {
  17. tagName: "td",
  18. text: "some text",
  19. },
  20. {
  21. tagName: "td",
  22. text: "some text 2",
  23. }
  24. ]
  25. }
  26. ],
  27. attrs:
  28. {
  29. border: 1,
  30. },
  31. }
  32. var table = someTree.tagName
  33. var tdchki = someTree.subTags[0].subTags
  34. var value = Object.keys(someTree.attrs)[0]
  35. var jsonString = "<" + table + " " + value + `= ` + someTree.attrs.border +`>\n<`
  36. + someTree.subTags[0].tagName + ">\n<"
  37. + tdchki[0].tagName + ">\n"
  38. + tdchki[0].text + "\n</"
  39. + tdchki[0].tagName + ">\n<"
  40. + tdchki[1].tagName + ">\n"
  41. + tdchki[1].text + "\n</"
  42. + tdchki[1].tagName + ">\n</"
  43. + someTree.subTags[0].tagName
  44. + ">\n</" + table + ">"
  45. console.log(jsonString)
  46. document.write(jsonString)
  47. </script>
  48. </body>
  49. </html>