BEGIN;
一般在做 ajax load 的时候,非常多人都不会考虑到须要浏览器支持前进后退功能,由于大部分人都不知道能够实现。
近期遇到这个问题,经过一小段研究,发现github已经有现成的开源工具使用,主要实现原理是利用html的锚点。即<a href="#xxx">。详情可查看https://github.com/balupton/jquery-history/tree/master
主要demo代码例如以下:
html
<ul> <li><a href="#ttt">ttttttttttttttt</a></li> <li><a href="#aaa">aaaaaaaaaaaaaaa</a></li> <li><a href="#bbb">bbbbbbbbbbbbbbb</a></li> <li><a href="#eee">eeeeeeeeeeeeeee</a></li> <li><a href="#mmm">mmmmmmmmmmmmmmm</a></li> </ul> <div id="showdiv" style=" 500px; height: 500px; border: 1px groove #e3e7ea;">default content</div>js
<script type="text/javascript"> $(function() { // 这里是共用的位置,通过state參数做操作 $.History.bind(function(state){ $('#showdiv').load('action/'+state+'.html'); }); // 这里是对某个链接做特殊操作 $.History.bind('bbb',function(state){ alert('点击了 bbb 链接,这是对 bbb 链接特殊处理位置'); }); }); </script>
相关问题:
state 參数:即超链接标签href="#xxx"中的xxx值。运行顺序:先运行特殊操作,再运行共用操作。
具体的源代码下载地址例如以下:
csdn资源下载地址:http://download.csdn.net/detail/cyzshenzhen/7487091
Git@OSC源代码托管地址:http://git.oschina.net/cyzshenzhen/jquery_history_demo
END;