javascript - how to copy div content to another page

前端 未结 4 1293
心在旅途
心在旅途 2021-01-01 08:03

I would like to make an automatic copy of a div content from page 1 an paste it in a div on page 2 ? What\'s the best, easiest way to achieve this ?

4条回答
  •  南笙
    南笙 (楼主)
    2021-01-01 08:29

    This is easier done with jQuery but you can get the html of a div using innerHTML as such:

    var div1 = document.getElementById('div1'),
    div1html = div1.innerHTML;
    

    Copying it to a div on a different page however would require some work..

    I know this doesn't answer your question entirely, I'm just giving you some insight as to how to get the html of an element. Copying it, using JS, could go something like this:

    var div2 = document.getElementById('div2')
    div2.appendChild(div1.cloneNode(true));
    

提交回复
热议问题