码迷,mamicode.com
首页 > 移动开发 > 详细

单页面应用(针对手机端)

时间:2015-03-17 19:33:26      阅读:394      评论:0      收藏:0      [点我收藏+]

标签:

关键字:history api+ajax+url route

  • 检测history api是否兼容:

   function supports_history_api() { return !!(window.history && history.pushState); }

1、history api

  1)先熟悉 HTML4 : history.back()以及history.go();

A) history.length:当前历史列表中的历史记录数(我大概测了下,IE6+是从0开始的,其他的是从1开始的;
B) history.go(n):前进或后退n条记录,当n=0或空时会刷新当前页;
C) history.back():后退一步;
D) history.forward():前进一步;

2、HTML5新增的API
A) history.pushState(data, title [, url]):往历史记录堆栈顶部添加一条记录;data会在onpopstate事件触发时作为参数传递过去;title为页面标题,当前所有浏览器都会 忽略此参数;url为页面地址,可选,缺省为当前页地址;
B) history.replaceState(data, title [, url]) :更改当前的历史记录,参数同上;
C) history.state:用于存储以上方法的data数据,不同浏览器的读写权限不一样;
D) window.onpopstate:响应pushState或replaceState的调用;

3、ajax 略

4、url route 涉及.net .NET Framework 4.5

帮助文档在 https://msdn.microsoft.com/zh-cn/library/system.web.routing.route.url.aspx

  1. 我们新建一个Login.aspx,有一个超链接 <a href=‘<%=GetRouteUrl("StudentRoute",new {id=1}) %>‘>Test</a>
  2. 之后在Global.asax里面添加RegisterRoutes方法

    void RegisterRoutes(RouteCollection routes)
    {
    routes.MapPageRoute(
    "StudentRoute", //路由名
    "Student/{id}.html", //路由URL
    "~/Test/Student.aspx" //处理路由的网页
    );
    }

    之后在 Application_Start注册一下

    void Application_Start(object sender, EventArgs e)

    {
    // 在应用程序启动时运行的代码
    RegisterRoutes(RouteTable.Routes);
    }
    最好运行效果为:http://localhost:5143/WebSite3/Student/1.html

    调用RouteData.Values["id"],就可以在另一页面取出传递的id了

单页面应用(针对手机端)

标签:

原文地址:http://www.cnblogs.com/babyfacer/p/4345032.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!