当用户点击其中一个按钮时,我有一些按钮,他们通过ajax更新页面内容,然后按钮被隐藏,一些新按钮可供用户使用。问题是,当我点击后退按钮时,它不会返回上一个功能。我希望用户回到上一组按钮,这是我的代码:
$(".buttonset1").click(function() {
$('#div1').css("display","none");
id = $(this).attr("value");
query = 'ajax.php?id='+id;
myQuery(query);
$('#div2').css("display","block");
});
$(".buttonset2").click(function() {
$('#div2').css("display","none");
value = $(this).attr("value");
query = 'ajax.php?id='+id+'&var1='value;
myQuery(query);
$('#div3').css("display","block");
});
现在向用户显示div2 .... myQuery函数执行ajax查询
function myQuery(url) {
if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
} else {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
document.getElementById("sql").innerHTML = xmlHttp.responseText;
}
}
xmlHttp.open('GET', url, true);
xmlHttp.send();
}
答案 0 :(得分:0)
解决它非常简单
History.Adapter.bind(window,'statechange',function(){ // Note: We are using statechange instead of popstate
var State = History.getState(); // Note: We are using History.getState() instead of event.state
var url = State.url;
myQuery(url);
});