当我点击侧边栏中的一个菜单时,我想加载一个新页面。但是JavaScript加载函数不起作用。
$(document).ready(function(){
$( 'button' ).click(function() {
$('#load').load('page1.html');
});
});<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="load"></div>
<button>Click to load a new page</button>
请帮帮忙。
发布于 2018-01-03 12:42:30
有几件事-
<html>
<head>
<title>Hello</title>
</head>
<body>
<div id="load" ></div>
<button id="clickme">Click to load a new page</button>
<script type="text/javascript">
(function() {
document.getElementById("clickme").onclick = function() {
fetch("page1.html")
.then(function(response) {
response.text().then(function (text) {
document.getElementById("load").innerHTML = text;
})
})
.catch(function(e) {
document.getElementById("load").innerHTML = `Error loading: ${e.message}`;
})
}
}());
</script>
</body>
</html>
https://stackoverflow.com/questions/48071027
复制相似问题