<ul id="choMenu" class="rel cho_menu">
<li><a href="ajax.php?area=pudong" class="cho_link cho_link_on">浦东区<span class="ml20">8</span></a></li>
<li><a href="ajax.php?area=baoshan" class="cho_link">宝山区<span class="ml20">7</span></a></li>
<li><a href="ajax.php?area=jiading" class="cho_link">嘉定区<span class="ml20">8</span></a></li>
<li><a href="ajax.php?area=qingpu" class="cho_link">青浦区<span class="ml20">3</span></a></li>
<li><a href="ajax.php?area=minhang" class="cho_link">闵行区<span class="ml20">4</span></a></li>
<li><a href="ajax.php?area=putuo" class="cho_link">普陀区<span class="ml20">2</span></a></li>
<li><a href="ajax.php?area=jinshan" class="cho_link">金山区<span class="ml20">3</span></a></li>
<li><a href="ajax.php?area=songjiang" class="cho_link">松江区<span class="ml20">3</span></a></li>
<li><a href="ajax.php?area=zhabei" class="cho_link">闸北区<span class="ml20">1</span></a></li>
<li><a href="ajax.php?area=fengxian" class="cho_link">奉贤区<span class="ml20">5</span></a></li>
<li><a href="ajax.php?area=huangpu" class="cho_link">黄浦区<span class="ml20">1</span></a></li>
<li><a href="ajax.php?area=changning" class="cho_link">长宁区<span class="ml20">1</span></a></li>
<li><a href="ajax.php?area=jingan" class="cho_link">静安区<span class="ml20">1</span></a></li>
<li><a href="ajax.php?area=zhoubian" class="cho_link">上海周边<span class="ml20">1</span></a></li>
</ul>

<script>
var eleMenuOn = null, eleListBox = $("#listBox"), tempList = $("#tempChoList").html()
, clMenuOn = "cho_link_on";

String.prototype.temp = function(obj) {
return this.replace(/\$\w+\$/gi, function(matchs) {
var returns = obj[matchs.replace(/\$/g, "")];
return (returns + "") == "undefined"? "": returns;
});
};
var eleMenus = $("#choMenu a").bind("click", function(event) {
var query = this.href.split("?")[1];
if (history.pushState && query && !$(this).hasClass(clMenuOn)) {
eleMenuOn && eleMenuOn.removeClass("cho_link_on");
eleMenuOn = $(this).addClass("cho_link_on");
eleListBox.html('<div class="cho_loading"></div>');
$.ajax({
url: this.href,
dataType: "json",
success: function(data) {
var html = '';
if ($.isArray(data)) {
$.each(data, function(i, obj) {
html += tempList.temp(obj);
});
}
eleListBox.html(html || '<div class="tc cr pt30">丫的没数据啊!</div>');
},
error: function() {
eleListBox.html('<div class="tc cr pt30">数据获取失败!</div>');
}
});

// history处理
var title = "上海3月开盘项目汇总-" + $(this).text().replace(/\d+$/, "");
document.title = title;
if (event && /\d/.test(event.button)) {
history.pushState({ title: title }, title, location.href.split("?")[0] + "?" + query);
}
}
return false;
});

var fnHashTrigger = function(target) {
var query = location.href.split("?")[1], eleTarget = target || null;
if (typeof query == "undefined") {
if (eleTarget = eleMenus.get(0)) {
history.replaceState(null, document.title, location.href.split("#")[0] + "?" + eleTarget.href.split("?")[1]) + location.hash;
fnHashTrigger(eleTarget);
}
} else {
eleMenus.each(function() {
if (eleTarget === null && this.href.split("?")[1] === query) {
eleTarget = this;
}
});

if (!eleTarget) {
history.replaceState(null, document.title, location.href.split("?")[0]);
fnHashTrigger();
} else {
$(eleTarget).trigger("click");
}
}
};
if (history.pushState) {
window.addEventListener("popstate", function() {
fnHashTrigger();
});

// 默认载入
fnHashTrigger();
}
</script>

HTML5 history API与ajax分页实例页面的更多相关文章

  1. HTML5 History API让ajax能回退到上一页

    HTML5 History API提供了一种功能,能让开发人员在不刷新整个页面的情况下修改站点的URL.这个功能很有用,例如通过一段JavaScript代码局部加载页面的内容,你希望通过改变当前页面的 ...

  2. window.history的跳转实质-HTML5 history API 解析

    在上一浏览器跳转行为的测试中,我们看到了通过不同的方法操作浏览器跳转时,它的刷新表现有所不同,在这一文章中,将看看,为何会产生这样的不同?其背后的实质是什么?浏览器的访问历史记录到底是如何运作的呢? ...

  3. HTML5 History API实现无刷新跳转

    在HTML5中, 新增了通过JS在浏览器历史记录中添加项目的功能. 在不刷新页面的前提下显示改变浏览器地址栏中的URL. 添加了当用户单击浏览器的后退按钮时触发的事件. 通过以上三点,可以实现在不刷新 ...

  4. HTML5 history API实践

    一.history API知识点总结 在HTML4中,我们已经可以使用window.history对象来控制历史记录的跳转,可以使用的方法包括: history.forward();//在历史记录中前 ...

  5. 转: html5 history api详解~很好的文章

    从Ajax翻页的问题说起 请想象你正在看一个视频下面的评论,在翻到十几页的时候,你发现一个写得稍长,但非常有趣的评论.正当你想要停下滚轮细看的时候,手残按到了F5.然后,页面刷新了,评论又回到了第一页 ...

  6. HTML5 history API,创造更好的浏览体验

    HTML5 history API有什么用呢? 从Ajax翻页的问题说起 请想象你正在看一个视频下面的评论,在翻到十几页的时候,你发现一个写得稍长,但非常有趣的评论.正当你想要停下滚轮细看的时候,手残 ...

  7. 转:HTML5 History API 详解

    从Ajax翻页的问题说起 请想象你正在看一个视频下面的评论,在翻到十几页的时候,你发现一个写得稍长,但非常有趣的评论.正当你想要停下滚轮细看的时候,手残按到了F5.然后,页面刷新了,评论又回到了第一页 ...

  8. 一篇文章图文并茂地带你轻松实践 HTML5 history api

    HTML5 history api 前言 由于笔者在网络上没有找到比较好的关于 history api 的实践案例,有的案例过于杂乱,没有重点,有些案例只是告诉读者 api 是什么,却没告诉怎么用,本 ...

  9. html5 history api

    1.html5 history api适用场景,个人理解最大的用处是配合ajax使用,使ajax拥有回退.前进的用户体验. 2.代码(dive into html5中的一个小例子) 1)fer.htm ...

随机推荐

  1. 洛谷 P3357 最长k可重线段集问题【最大流】

    pre:http://www.cnblogs.com/lokiii/p/8435499.html 和最长k可重区间集问题差不多,也就是价值的计算方法不一样,但是注意这里可能会有x0==x1的情况也就是 ...

  2. iOS 上传APP到AppStore 卡在 Authenticating with the iTunes store 提示

    上传APP的时候,遇到了问题,一直卡在Authenticating with the iTunes store提示这里, 解决办法:在Application Loader里面登录需要上传APP的开发者 ...

  3. _bzoj1013 [JSOI2008]球形空间产生器sphere【高斯消元】

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1013 保存高斯消元模版. ps,这一题的英文名字是ヨスガノソラ的开发商~^_^ #inclu ...

  4. linux 前台后台程序切换命令总结

    1.在Linux终端运行命令的时候,在命令末尾加上 & 符号,就可以让程序在后台运行 root@Ubuntu$ ./tcpserv01 & 2.如果程序正在前台运行,可以使用 Ctrl ...

  5. 题解报告:NYOJ #311完全背包(恰好装满)

    描述: 直接说题意,完全背包定义有N种物品和一个容量为V的背包,每种物品都有无限件可用.第i种物品的体积是c,价值是w.求解将哪些物品装入背包可使这些物品的体积总和不超过背包容量,且价值总和最大.本题 ...

  6. 题解报告:hdu 1503 Advanced Fruits(LCS加强版)

    Problem Description The company "21st Century Fruits" has specialized in creating new sort ...

  7. Service官方教程(2)*IntentService与Service示例、onStartCommand()3个返回值的含义。

    1.Creating a Started Service A started service is one that another component starts by calling start ...

  8. JAVA中abstract,interface,final,static语法

    转自:http://www.cnblogs.com/yueue/archive/2010/04/20/1715863.html 一,抽象类:abstract     1,只要有一个或一个以上抽象方法的 ...

  9. [转]无废话SharePoint入门教程二[SharePoint发展、工具及术语]

    本文转自:http://www.cnblogs.com/iamlilinfeng/p/3186919.html 一.前言 1.由于上一篇文章的标题命名失误,此篇标题写给百度搜索”什么是SharePoi ...

  10. 构建微服务开发环境5————安装Node.js

    [内容指引] 下载Node.js: Mac下安装Node.js: Windows下安装Node.js; 查看node和npm的版本. 一.下载Node.js 访问Node.js官网:https://n ...