Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

如何将固定格式DOM转换成对象?

$
0
0

如将下面这个dom结构转成对象?

<h1>A</h1>
  <h2>2</h2>
  <h2>3</h2>
  <h3>content1</h3>
  <h3>content2</h3>
  <h2>4</h2>
  <h1>B</h1>
  <h2>5</h2>
  <h1>C</h1>
  <h2>6</h2>

转换成

var obj= {
          A: {
            '2': '',
            '3': {
              content1: '',
              content2: ''
            },
            '4': ''
          },
          B: {
            '5': ''
          },
          C: {
            '6': ''
          }
        }


Viewing all articles
Browse latest Browse all 14821

Trending Articles