javascript:jquery.history.js使用方法
2010-12-09 16:44
561 查看
step1:download jquery.history.js
step2:create a test page as following:
说明:当页面执行javascript代码后,地址栏能前进和后退。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
#mydiv
{
border: 1px solid blue;
width: 400px;
height: 200px;
}
</style>
<script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="Scripts/jquery.history.js" type="text/javascript"></script>
<script type="text/javascript">
function showMsg(msg) {//you can ajax request
$('#mydiv').html(msg);
}
$(function () {
$("#link1").bind("click", function () { window.location.hash = "#link1"; });
$("#link2").bind("click", function () { window.location.hash = "#link2"; });
$("#link3").bind("click", function () { window.location.hash = "#link3"; });
$.history.init(function (hash) {
var msg;
if (hash) {
msg= hash;
}
else
{
msg= "no set hash value"
}
showMsg(msg);
});
})
</script>
</head>
<body>
<input type="button" value="button1" id="link1" />
<input type="button" value="button2" id="link2" />
<input type="button" value="button3" id="link3" />
<hr />
<div id="mydiv">
</div>
</body>
</html>
step2:create a test page as following:
说明:当页面执行javascript代码后,地址栏能前进和后退。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
#mydiv
{
border: 1px solid blue;
width: 400px;
height: 200px;
}
</style>
<script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="Scripts/jquery.history.js" type="text/javascript"></script>
<script type="text/javascript">
function showMsg(msg) {//you can ajax request
$('#mydiv').html(msg);
}
$(function () {
$("#link1").bind("click", function () { window.location.hash = "#link1"; });
$("#link2").bind("click", function () { window.location.hash = "#link2"; });
$("#link3").bind("click", function () { window.location.hash = "#link3"; });
$.history.init(function (hash) {
var msg;
if (hash) {
msg= hash;
}
else
{
msg= "no set hash value"
}
showMsg(msg);
});
})
</script>
</head>
<body>
<input type="button" value="button1" id="link1" />
<input type="button" value="button2" id="link2" />
<input type="button" value="button3" id="link3" />
<hr />
<div id="mydiv">
</div>
</body>
</html>
相关文章推荐
- javascript attachEvent和addEventListener 使用方法--http://www.diybl.com/course/1_web/javascript/jsjs/20071226/94592.html
- jquery.cookie.js的介绍与使用方法
- 使用jQuery动态加载js脚本文件的方法
- 要想使用attr等jQuery对象的方法,就要将普通的JavaScript对象转换成jQuery对象
- 一道js面试题:请写出尽可能多的使用JavaScript产生一个Image 标签的方法
- 缓冲加载图片的 jQuery 插件 lazyload.js 使用方法详解
- 使用jquery的load方法设计动态加载,并解决被加载页面JavaScript失效问题
- 缓冲加载图片的 jQuery 插件 lazyload.js 使用方法详解
- js加载之使用DOM方法动态加载Javascript文件
- jQuery animate()实现背景色渐变效果的处理方法【使用jQuery.color.js插件】
- jQuery.Form.js使用方法
- jQuery-全屏滚动插件【fullPage.js】API 使用方法总结
- 使用js仿写jquery中$.ajax()方法
- jquery.cookie.js 使用方法
- jquery分页插件jquery.pagination.js使用方法解析
- jquery.slides.js 幻灯片脚本使用方法
- JS/Jquery使用过程中遇到的问题和解决方法
- JS和JQuery使用localStorage方法
- javascript(js)使用eval方法加密过的函数解密方法
- jquery.nicescroll.min.js滚动条使用方法