Load html into div without changing the rest of page

后端 未结 2 1404
猫巷女王i
猫巷女王i 2020-12-19 13:53

So I\'ve seen tons of people asking how to load html into a div, and my code does that fine....but then the rest of the page changes when I load the html into the div.

相关标签:
2条回答
  • 2020-12-19 14:13

    You have to write your html code into a <body> </body>

    <html> 
    <head> 
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
    <script> 
    $(function() {
    $("#includedContent").load("b.html"); 
    }); 
    </script> 
    </head>
    
    <body>
     <div id="includedContent"></div>
     <h1>This is why I rule</h1>
    </body>
    </html>
    
    0 讨论(0)
  • 2020-12-19 14:21

    All your HTML markup is in the head section not the body

    try this:

    <html> 
    <head> 
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
    
    <script> 
    $(function() {
    $("#includedContent").load("b.html"); 
    }); 
    </script> 
    
    </head>
    <body>
         <div id="includedContent"></div>
         <h1>This is why I rule</h1>
    </body>
    </html>
    
    0 讨论(0)
提交回复
热议问题