我正在尝试创建一个全局页面,它只会更改内容而不是完全加载新页面。 当我尝试在home.php页面上调用loadPage函数时,它只是告诉我loadPage函数没有被定义。 问题是我认为,在加载新内容时必须重新创建该功能......
全局网页代码(HTML):
<!-- Please note: this is the part that loads the page, and displays the loading image -->
<script type="text/javascript" src="jQuery/jQuery.js"></script>
<script type="text/javascript" src="js/loadPage.js"></script>
<link type="text/css" rel="stylesheet" href="css/style-loading.css">
<img class="loading-img" src="images/loading.gif">
<!-- End of note -->
<!doctype html>
<html>
</html>
页面加载代码(JS):
//Copyright © 2016 Dynavio Cooperative
var currentPage = null;
$(document).ready(function()
{
loadPage();
});
function loadPage(pageToLoad)
{
$(".loading-img").removeAttr("style");
if(typeof pageToLoad == "undefined")
{
if(currentPage == null)
{
$("html").load("pages/home.php", function()
{
$(".loading-img").css("display", "none");
});
}
}
else
{
$("html").load(pageToLoad, function()
{
$(".loading-img").css("display", "none");
});
}
}
home.php代码(HTML):
<!-- Copyright © 2016 Dynavio Cooperative -->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Dynavio">
<meta name="keywords" content="Dynavio,Cooperative,Administration">
<meta name="author" content="Dynavio Cooperative">
<title>Dynavio - Homepage</title>
<!-- Css styles -->
<link type="text/css" rel="stylesheet" href="css/plugins/font-awesome-4.6.1/css/font-awesome.min.css">
<link type="text/css" rel="stylesheet" href="css/style-main-global.css">
<link type="text/css" rel="stylesheet" href="css/style-fonts.css">
<link type="text/css" rel="stylesheet" href="css/style-navbar.css">
<link type="text/css" rel="stylesheet" href="css/style-slider.css">
<!-- End of Css styles -->
<script type="text/javascript" src="jQuery/plugins/Slides-SlidesJS-3/source/jquery.slides.min.js"></script>
<script type="text/javascript" src="js/sliderInit.js"></script>
<!-- Javascript -->
</head>
<body>
<div class="navbar">
<img src="images/logo.png" class="nav-logo">
<ul class="nav-items">
<li class="nav-item active">Homepage</li>
<li class="nav-item">Products</li>
<li class="nav-item">Company</li>
<li class="nav-item">Research</li>
<li class="nav-item">Contact</li>
<li class="nav-item" onClick="loadpage(pages/login.php);">Login</li>
</ul>
</div>
<div class="intro-slider slider">
<img src="images/example1.png">
<img src="images/example2.png">
</div>
<div class="products">
</div>
</body>
<!-- Copyright © 2016 Dynavio Cooperative -->
答案 0 :(得分:0)
HTML中存在问题。我知道该代码只是代码的一部分,但doctype定义应始终位于第一行。
然后,我看不到<html>
标签打开。我希望它在你的代码的其他部分。
答案 1 :(得分:0)
原来问题是因为函数名称区分大小写......