weixin_33720078 2019-06-06 08:13 采纳率: 0%
浏览 36

用ajax加载主要内容

I've got a navigation bar div on all my .html page. To not copy paste the nav-bar code on every page I've created an .html page with the code and I print it on every page via jquery like this:

<div id="includeNavbar"></div>

And the code to actually print it is:

$(function(){
      $("#includeNavbar").load("navbar.html"); 
});

Is there a way to keep the nav bar loaded and load the remaining content via jquery but still using this type of printing method?

I'm using the latest Bootstrap version

  • 写回答

1条回答 默认 最新

  • elliott.david 2019-06-06 09:17
    关注

    Your code is the simple way to load a HTML file in other html file.. keep it up.

    And also you can change your html file type into php and then you can include or require that you want place .

    Like this

    nav-bar.php

    <ul class="nav">
      <li class="nav-item">
        <a class="nav-link active" href="#">Active</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
      </li>
    </ul>
    

    And your Main.php page that where you want another page.

    Main.php

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    
    <?php require 'nav-bar.php'?>   
    
    
    </body>
    </html>
    

    Hope you find the answer. :)

    评论

报告相同问题?

悬赏问题

  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题