加载并添加到正文jquery

时间:2016-09-18 16:43:57

标签: javascript php jquery html

当我尝试将多个文件加载到脚本中时,它不会添加,它会替换。

这是我的身体部位:

<body class="about-us Home-two Home-three">
<!-- jquery
============================================ -->
<script src="/assets/js/vendor/jquery-1.11.3.min.js"></script>
<!-- bootstrap JS
============================================ -->
<script src="/assets/js/bootstrap.min.js"></script>
<!-- wow JS
============================================ -->
<script src="/assets/js/wow.min.js"></script>
<!-- price-slider JS
============================================ -->
<script src="/assets/js/jquery-price-slider.js"></script>
<!-- meanmenu JS
============================================ -->
<script src="/assets/js/jquery.meanmenu.js"></script>
<!-- owl.carousel JS
============================================ -->
<script src="/assets/js/owl.carousel.min.js"></script>
<!-- scrollUp JS
============================================ -->
<script src="/assets/js/jquery.scrollUp.min.js"></script>
<!-- plugins JS
============================================ -->
<script src="/assets/js/plugins.js"></script>
<!-- Nivo slider js
============================================ -->
<script src="/assets/custom-slider/js/jquery.nivo.slider.js" type="text/javascript"></script>
<script src="/assets/custom-slider/home.js" type="text/javascript"></script>
<!-- main JS
============================================ -->
<script src="/assets/js/url.js"></script>
<script src="/assets/js/main.js"></script>
<script type="text/javascript">
    $(function() {
        getPage(url('2'));
    });
</script>
</body>

我想将header.php和banner.php添加到此

我尝试了这段代码:

$(".about-us").load("/parts/header.php").prependTo("body");
$(".about-us").load("/parts/banner.php").prependTo("body");

但只添加了标题。如何将多个脚本加载到正文中?

1 个答案:

答案 0 :(得分:0)

如果您尝试将.load()的回复添加到.about-usbody,请将$.get()替换为.load().load()替换现有内容。

$.when($.get("/parts/header.php"), $.get("/parts/banner.php"))
.then(function(header, banner) {
  $.each([header.shift(), banner.shift()], function(index, content) {
    $(".about-us").prepend(content);
  });
});