javascript - How to add points to the DOM of the page and add it to the DOM element of the main page
世界只因有你
世界只因有你 2017-05-18 10:46:55
0
3
462

The main page index.html is like this

<body>
    <p id="container">
        
    </p>
    <script src="js/main.js"></script>
</body>

Page page_1.html For the convenience of operation, there is only dom block and no Body html tag

<p class="page_1">
    page_1
</p>

There are many such sub-pages page_2.html, page_3.html, page_4.html...

<p class="page_2">
    page_2
</p>

<p class="page_3">
    page_3
</p>

Now I want to add the content of page_1.html page_3.html to the <p id="container"> of index.html as needed. The execution environment can be react.js and the backend is added. .

Seeking popular science

世界只因有你
世界只因有你

reply all(3)
刘奇

I don’t know about react. For jquery, just use load(). I guess loading through ajax is also possible. However, there are a few points to pay attention to:
1. It cannot be cross-domain.
2. Be sure to use it when calling the path. Address with domain name, such as changing $.get("page_1.html") to $.get("http://xxxxxxx/page_1.html")
This should be enough

Peter_Zhu

Isn’t this what React itself is doing?

<p id="container">
    {(condition) ? <Page1> : <Page2>}
</p>

The above code only expresses a meaning, and the judgment part can be more complicated. "Pages" are all modules, which can be loaded according to conditions.

Peter_Zhu

Is the suffix of page1 html? Then you can only add iframe

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template