jQuery mobile类库使用时加载导航历史的方法简介


Posted in Javascript onDecember 04, 2015
jQuery.mobile.navigate( url [, data ] )

改变URL和跟踪历史。作品为浏览器和无历史新的API

  • url:是必须的参数。类型:字符串
  • data:是可选的参数。类型:对象。 

更改哈希片段两次然后日志提供导航事件数据时,浏览器向后移动的历史

// Starting at http://example.com/
// Alter the URL: http://example.com/ => http://example.com/#foo

$.mobile.navigate( "#foo", { info: "info about the #foo hash" });
 
// Alter the URL: http://example.com/#foo => http://example.com/#bar

$.mobile.navigate( "#bar" );
 
// Bind to the navigate event

$( window ).on( "navigate", function( event, data ) {
 console.log( data.state.info );
 console.log( data.state.direction )
 console.log( data.state.url )
 console.log( data.state.hash )
});


 
// Alter the URL: http://example.com/#bar => http://example.com/#foo

window.history.back();
 
// From the `navigate` binding on the window, console output:
// => "info about the #foo hash"
// => "back"
// => "http://example.com/#bar
// => "#bar"

劫持一个链接点击使用导航方法,然后加载内容

// Starting at http://example.com/
// Define a click binding for all anchors in the page

$( "a" ).on( "click", function( event ) {
 
 // Prevent the usual navigation behavior

 event.preventDefault();
 
 // Alter the url according to the anchor's href attribute, and
 // store the data-foo attribute information with the url
 $.mobile.navigate( this.attr( "href" ), { foo: this.attr( "data-foo" ) });
 
 // Hypothetical content alteration based on the url. E.g, make
 // an ajax request for JSON data and render a template into the page.

 alterContent( this.attr( "href" ) );
});
Javascript 相关文章推荐
JavaScript 新手24条实用建议[TUTS+]
Jun 21 Javascript
javascript 学习笔记(六)浏览器类型及版本信息检测代码
Apr 08 Javascript
自己封装的javascript事件队列函数版
Jun 12 Javascript
微信小程序商品详情页规格属性选择示例代码
Oct 30 Javascript
在knockoutjs 上自己实现的flux(实例讲解)
Dec 18 Javascript
Angular6 用户自定义标签开发的实现方法
Jan 08 Javascript
Vue中多个元素、组件的过渡及列表过渡的方法示例
Feb 13 Javascript
详解如何给React-Router添加路由页面切换时的过渡动画
Apr 25 Javascript
NProgress显示顶部进度条效果及使用详解
Sep 21 Javascript
使用PreloadJS加载图片资源的基础方法详解
Feb 03 Javascript
解决vue的router组件component在import时不能使用变量问题
Jul 26 Javascript
在HTML中使用JavaScript的两种方法
Dec 24 Javascript
jQuery mobile转换url地址及获取url中目录部分的方法
Dec 04 #Javascript
JavaScript原生xmlHttp与jquery的ajax方法json数据格式实例
Dec 04 #Javascript
使用jQuery mobile库检测url绝对地址和相对地址的方法
Dec 04 #Javascript
jQuery移动web开发之页面跳转和加载外部页面的实现
Dec 04 #Javascript
详解JavaScript逻辑And运算符
Dec 04 #Javascript
JavaScript encodeURI 和encodeURIComponent
Dec 04 #Javascript
详解JavaScript逻辑Not运算符
Dec 04 #Javascript
You might like
php数据入库前清理 注意php intval与mysql的int取值范围不同
2010/12/12 PHP
解析zend studio中直接导入svn中的项目的方法步骤
2013/06/21 PHP
php合并js请求的例子
2013/11/01 PHP
html静态页面调用php文件的方法
2014/11/13 PHP
Yii框架创建cronjob定时任务的方法分析
2017/05/23 PHP
jquery 插件实现图片延迟加载效果代码
2010/02/06 Javascript
javascript温习的一些笔记 基础常用知识小结
2011/06/22 Javascript
jquery获取html元素的绝对位置和相对位置的方法
2014/06/20 Javascript
jQuery实现的tab标签切换效果示例
2016/09/05 Javascript
JavaScript 监控微信浏览器且自带返回按钮时间
2016/11/27 Javascript
js实现省份下拉菜单效果
2017/02/15 Javascript
JS去掉字符串前后空格或去掉所有空格的用法
2017/03/25 Javascript
jQuery事件对象的属性和方法详解
2017/09/09 jQuery
浅谈Vue-cli 命令行工具分析
2017/11/22 Javascript
解决Vue2.x父组件与子组件之间的双向绑定问题
2018/03/06 Javascript
React-router4路由监听的实现
2018/08/07 Javascript
Nuxt配合Node在实际生产中的应用详解
2018/08/07 Javascript
extjs4图表绘制之折线图实现方法分析
2020/03/06 Javascript
解决vue net :ERR_CONNECTION_REFUSED报错问题
2020/08/13 Javascript
浅谈Python的异常处理
2016/06/19 Python
pygame实现贪吃蛇游戏(下)
2019/10/29 Python
python dumps和loads区别详解
2020/02/04 Python
matplotlib制作雷达图报错ValueError的实现
2021/01/05 Python
优秀学生干部个人的自我评价
2013/10/04 职场文书
四好少年事迹材料
2014/01/12 职场文书
楼面部长岗位职责范本
2014/02/14 职场文书
班级德育工作实施方案
2014/02/21 职场文书
通用自荐信范文
2014/03/14 职场文书
高中同学会活动方案
2014/08/14 职场文书
群众路线专项整治工作情况报告
2014/10/28 职场文书
辛亥革命观后感
2015/06/02 职场文书
音乐之声观后感
2015/06/04 职场文书
婚育证明格式
2015/06/17 职场文书
Vue.js 带下拉选项的输入框(Textbox with Dropdown)组件
2021/04/17 Vue.js
你知道Java Spring的两种事务吗
2022/03/16 Java/Android
使用HttpSessionListener监听器实战
2022/03/17 Java/Android