本篇内容介绍了“html5中preload的概念是什么”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
顺晟科技
2021-07-04 22:13:22
153
我已经通过JavaScript创建了哈希URL加载函数。我面临一个问题,即单击href
标记时无法显示加载div。
我的代码工作正常,当我重新加载页面时,它只将加载div显示为<div class="loader"><div>
,但它在单击链接上不工作。
请帮助我,我如何在单击哈希链接时实现该函数。
function loadcontent(hash) {
if (hash == "") {
hash = "./default-page.html";
}
$("html body").animate({
scrollTop: 0
}, "600", "swing");
$("div.main-content-inner").load("pagefolder/" + hash);
}
$(window).on("hashchange", function() {
loadcontent(location.hash.slice(1));
});
var url = window.location.href;
var hash = url.substring(url.indexOf("#") + 1);
if (hash === url) {
hash = "./default-page.html";
}
$("body").append('<div class="loader"><div>');
$("body> div").load("pages/mypage/" + hash, function(responseTxt, statusTxt, jqXHR) {
if (statusTxt == "success") {
$("div.loader").remove();
} else {
if (statusTxt == "error") {
$("div.loader").remove();
alert("Error : " + jqXHR.status + " " + jqXHR.statusText);
return false;
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="#home">home</a>
<a href="#about">about</a>
<a href="#contactus">contact us</a>
顺晟科技:
20
2022-10
19
2022-10
19
2022-10
19
2022-10
19
2022-10
18
2022-10