【发布时间】:2011-10-16 04:22:34
【问题描述】:
我使用 hashchange 事件来检测用户何时单击浏览器中的后退按钮并相应地更改 URL。有没有更好的方法来进行分页?在用户单击我的分页控件后,我目前正在更改 URL,如下所示:
$(".pager").click(function(){
var start = null;
if ($.browser.msie) {
start = $(this).attr('href').slice($(this).attr('href').indexOf('#')+1);
}
else {
start = $(this).attr('href').substr(1);
}
$('#start').val(start);
$.post("visits_results.php", $("#profile_form_id").serialize(),
function(data) {
$('#search_results').html(data);
location.href = "#visits=" + start;
});
return false;
});
我的 javascript 检测后退按钮如下所示:
function myHashChangeCallback(hash) {
if (hash == "") {
$("#loadImage").show();
var no_cache = new Date().getTime();
$('#main').load("home.php?cache=" + no_cache, function () {
$("#loadImage").hide();
});
return false;
}
else {
// adding code to parse the hash URL and see what page I'm on...is there a better way?;
}
}
function hashCheck() {
var hash = window.location.hash;
if (hash != _hash) {
_hash = hash;
myHashChangeCallback(hash);
}
}
我目前计划检查每个主题标签和值,以查看我应该加载哪个页面,除非有更好更有效的方法。
有什么想法或建议吗?
【问题讨论】:
标签: php javascript jquery pagination