$("#nav").load("nav.html");
#nav为防止其他页面代码的容器,nav.html为要加载的外部代码文件
容器代码
<nav class="mt-2"> <ul id="nav"> </ul> </nav>