12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <script>
- var someTree = {
- tagName: "table", //html tag
- subTags: [ //вложенные тэги
- {
- tagName: "tr",
- subTags: [
- {
- tagName: "td",
- text: "some text",
- },
- {
- tagName: "td",
- text: "some text 2",
- }
- ]
- }
- ],
- attrs:
- {
- border: 1,
- },
- }
- var table = someTree.tagName
- var tdchki = someTree.subTags[0].subTags
- var value = Object.keys(someTree.attrs)[0]
- var jsonString = "<" + table + " " + value + `= ` + someTree.attrs.border +`>\n<`
- + someTree.subTags[0].tagName + ">\n<"
- + tdchki[0].tagName + ">\n"
- + tdchki[0].text + "\n</"
- + tdchki[0].tagName + ">\n<"
- + tdchki[1].tagName + ">\n"
- + tdchki[1].text + "\n</"
- + tdchki[1].tagName + ">\n</"
- + someTree.subTags[0].tagName
- + ">\n</" + table + ">"
- console.log(jsonString)
- document.write(jsonString)
- </script>
- </body>
- </html>
|