HTML5 history API与ajax分页实例页面
<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分页实例页面的更多相关文章
- HTML5 History API让ajax能回退到上一页
HTML5 History API提供了一种功能,能让开发人员在不刷新整个页面的情况下修改站点的URL.这个功能很有用,例如通过一段JavaScript代码局部加载页面的内容,你希望通过改变当前页面的 ...
- window.history的跳转实质-HTML5 history API 解析
在上一浏览器跳转行为的测试中,我们看到了通过不同的方法操作浏览器跳转时,它的刷新表现有所不同,在这一文章中,将看看,为何会产生这样的不同?其背后的实质是什么?浏览器的访问历史记录到底是如何运作的呢? ...
- HTML5 History API实现无刷新跳转
在HTML5中, 新增了通过JS在浏览器历史记录中添加项目的功能. 在不刷新页面的前提下显示改变浏览器地址栏中的URL. 添加了当用户单击浏览器的后退按钮时触发的事件. 通过以上三点,可以实现在不刷新 ...
- HTML5 history API实践
一.history API知识点总结 在HTML4中,我们已经可以使用window.history对象来控制历史记录的跳转,可以使用的方法包括: history.forward();//在历史记录中前 ...
- 转: html5 history api详解~很好的文章
从Ajax翻页的问题说起 请想象你正在看一个视频下面的评论,在翻到十几页的时候,你发现一个写得稍长,但非常有趣的评论.正当你想要停下滚轮细看的时候,手残按到了F5.然后,页面刷新了,评论又回到了第一页 ...
- HTML5 history API,创造更好的浏览体验
HTML5 history API有什么用呢? 从Ajax翻页的问题说起 请想象你正在看一个视频下面的评论,在翻到十几页的时候,你发现一个写得稍长,但非常有趣的评论.正当你想要停下滚轮细看的时候,手残 ...
- 转:HTML5 History API 详解
从Ajax翻页的问题说起 请想象你正在看一个视频下面的评论,在翻到十几页的时候,你发现一个写得稍长,但非常有趣的评论.正当你想要停下滚轮细看的时候,手残按到了F5.然后,页面刷新了,评论又回到了第一页 ...
- 一篇文章图文并茂地带你轻松实践 HTML5 history api
HTML5 history api 前言 由于笔者在网络上没有找到比较好的关于 history api 的实践案例,有的案例过于杂乱,没有重点,有些案例只是告诉读者 api 是什么,却没告诉怎么用,本 ...
- html5 history api
1.html5 history api适用场景,个人理解最大的用处是配合ajax使用,使ajax拥有回退.前进的用户体验. 2.代码(dive into html5中的一个小例子) 1)fer.htm ...
随机推荐
- IDE工具的[多行光标编辑模式]
Sublime Text3:Ctrl+Alt+上下键 Eclipse:Shift+Alt+A,进入退出多光标模式 IDEA:Shift + ctrl + alt + 鼠标左键 收集链接 IDEA:ht ...
- E20180309-hm-xa
conformance n. 顺应,一致; symmetric adj. 相称性的,均衡的; raw adj. 生的,未加工的; 无经验的; 新近完成的; 发炎的,疼痛的; exceed ...
- bzoj2720: [Violet 5]列队春游(概率期望+组合数学)
Description Input Output Sample Input Sample Output HINT 数学题都这么骚的么……怎么推出来的啊……我是真的想不出来…… 首先,要算总的视 ...
- js 几秒之后就不断的执行
function url() { $.ajax({ url: "AA.ashx", data: { ID: "gggg ...
- jQuery笔记之data方法
成品图如下所示: 搭建HTML+CSS结构 <style> /* 给tpl设置为不可见,因为我们不需要用到他,我们只是要克隆他身上的东西,克隆完就把他删掉.就跟渣男一样!!!*/ .tpl ...
- PowerDesigner在PDM转换为sql脚本时报错Generation aborted due to errors detected during the verification of the mod
在设计概念数据模型(CDM)之后,转换为物理数据模型(PDM),之后转换为sql脚本时报错Generation aborted due to errors detected during the ve ...
- HTML_CSS入门学习
1 HTML 简介 下面解释什么是HTML,以及HTML标签和HTML文档的含义. 1.1 什么是 HTML? HTML 是用来描述网页的一种语言. HTML 指的是超文本标记语言 (Hyper Te ...
- 转】在Ubuntu中安装Cassandra
原博文出自于: http://blog.fens.me/category/%E6%95%B0%E6%8D%AE%E5%BA%93/ 感谢! Posted: Mar 22, 2014 Tags: cas ...
- ASP.NET URLRewriter重写
URLRewriter重写是微软官方出的第三方重写插件 下载地址:http://download.csdn.net/detail/ysn1314/5421587 下载后在项目中添加引用,然后再配置文件 ...
- IIS7 网站发布
选择“网站” 添加网站