看看你是否可以借给我一把,我试图应用history.pushState jquery代码不起作用,我对如何实现history.pushState知之甚少,并在这方面请求一点帮助。然后我点击了我的代码...
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Documento sin título</title>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js' type='text/javascript'/></script>
<script>
function cargar(div, desde)
{
$(div).load(desde, function() {
});
init();
$(document).on("click", "a, area", function() {
var href = $(this).attr("href");
history.pushState({}, '', href);
$main.load(href + " main>*", ajaxLoad);
return false;
});
history.pushState(pageData, pageData.title, pageURL);
}
</script>
</head>
<body>
<div id="botones">
<ul class="menu-galeria">
<li><a href="#1" onClick="cargar('#cambia','1.php')">CAMBIO 1</a></li>
<li><a href="#2" onClick="cargar('#cambia','2.php')">CAMBIO 2</a></li>
</ul>
</div>
<div id="cambia">
Hola cambio
</div>
</body>
</html>
1.php和2.php是简单的文字
答案 0 :(得分:0)
我已经以这种方式找到了解决方案,因为它可以帮助别人。
<!doctype html>
<html>
<head>
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
<script>
$( document ).ready(function() {
$( ".loadContent a" ).click(function() {
var file = $(this).data("file");
$('#content').load(file, function(){
window.history.pushState({id: file}, file, file);
return false;
})
});
});
</script>
</head>
<body>
<ul class="loadContent">
<li><a href="#" data-file="file1.php">bot1</a></li>
<li><a href="#" data-file="file2.php">bot2</a></li>
</ul>
<div id="content">
I'm going to change
</div>
</body>
</html>