事件变量被传递给change
函数,其属性为:value, path, pathNames, parameterNames, parameters, queryString
。您要监控的房产是pathNames
。
这里有一些片断,我放在一起,可以帮助你跟踪你有多深,以及究竟是什么发生了变化:
var $current_path = window.location.hash;
$.address.change(function(event) {
// get the difference in the two paths
$changed_path = event.path.replace(new RegExp('^'+$current_path,'i'), '');
// make sure we update the current path
$current_path = event.path;
// how deep is the new path?
$level = event.pathNames.length;
// break the changed part into segments, ignoring leading/trailing slashes
$changed_path_array = $changed_path.replace(/^\/|\/$/g, '').split('/');
// let's see what level actually changed from the current path
$changed_level = $level - $changed_path_array.length;
});
然后,您可以通过使用整理功能的其余部分新的深度与细分阵列结合,精确地确定需要更新的内容。基于$ current_path,您可能正在执行全新的页面加载,或者只是在页面某处发生微小的更改。
你可以发布一些你的代码吗? – 2011-05-03 01:04:02