万能的路由 在一个网站上看到的 实现局部加载
来源:互联网 发布:sql case when怎么用 编辑:程序博客网 时间:2024/06/06 05:06
<!DOCTYPE html><html><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="keywords" content="javascript" /><meta name="description" content="Helloweba演示平台,演示XHTML、CSS、jquery、PHP案例和示例" /><title>演示:Javascript实现前端简单路由</title><link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css"><link rel="stylesheet" type="text/css" href="../../css/demo.css"><style>.text-right li{padding: 10px}#result{height: 200px; line-height: 200px; font-size: 2rem; text-align: center; }</style></head><body><div class="container"> <header> <div class="row"> <div class="col-md-3 col-xs-12"><h1 class="logo"><a href="http://www.helloweba.com" title="返回helloweba首页">helloweba</a></h1></div> <div class="col-md-9 text-right"></div> </div> </header> <div class="row main" style="min-height:500px"> <div class="col-md-12"> <h2 class="top_title"><span class="glyphicon glyphicon-menu-left" aria-hidden="true"></span><a href="http://www.helloweba.com/view-blog-385.html">Javascript实现前端简单路由</a></h2> <div class="row" style="margin-top:30px"> <div class="col-md-3"> <ul class="text-right"> <li><a href="#/">首页</a></li> <li><a href="#/product">产品</a></li> <li><a href="#/server">服务</a></li> </ul> </div> <div class="col-md-7"> <div id="result"></div> </div> </div> </div> </div> <footer> <p>Powered by helloweba.com 允许转载、修改和使用本站的DEMO,但请注明出处:<a href="http://www.helloweba.com">www.helloweba.com</a></p> </footer></div><script type="text/javascript">function Router(){ this.routes = {}; this.curUrl = ''; this.route = function(path, callback){ this.routes[path] = callback || function(){}; }; this.refresh = function(){ this.curUrl = location.hash.slice(1) || '/'; this.routes[this.curUrl](); }; this.init = function(){ window.addEventListener('load', this.refresh.bind(this), false); window.addEventListener('hashchange', this.refresh.bind(this), false); }}var R = new Router();R.init();</script><script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script><script> R.route('/', function() { //跳转第一页 $("#result").load("./demo1.html",function (data) { $(this).html(data) }) }); R.route('/product', function() { //跳转第二页 $("#result").load("./demo2.html",function (data) { $(this).html(data) }) }); R.route('/server', function() { //跳转第3页 $("#result").load("./demo3.html",function (data) { $(this).html(data) }) });</script></body></html>
阅读全文
0 0
- 万能的路由 在一个网站上看到的 实现局部加载
- 在expert C上看到的一个好玩的东西
- 在twitter上看到的一个有趣的算法
- 在一个论坛上看到的,可以学习与借鉴!
- 怎样在一个控件上设置字体局部的效果
- NS2上实现一个简单的路由协议
- asp网站在iis7上配制后打不开!在官网看到的结果
- 偶然在公司的网站上看到的 http://www.pincl.net/animal.htm
- 何时能在我的网站上看到展示 Google 广告
- 经常看到在一个大的电容上还并联一个小电容,这是为什么?
- 经常看到在一个大的电容上还并联一个小电容,这是为什么?
- 在csdn上看到的怪问题
- 在一本小说上看到的
- 在stackexchange上看到的一则笑话
- 在网易上看到的一个帖子-假如乔布斯出生在中国
- 万能的RecyclerViewAdapter,支持上拉加载、添加HeadView
- 在淘宝一个4钻卖家的主页上看到的一首诗,觉得很好。
- 分享一个在osc上看到的java版的截图软件
- (116)在线会话节点
- Android应用保存数据到系统数据库(Settings.System.putString、Settings.System.putInt)
- 浅谈语义角色
- 使用v$object_usage监控索引
- H5 31
- 万能的路由 在一个网站上看到的 实现局部加载
- MySql模糊查询like通配符使用详细介绍
- python -m SimpleHTTPServer
- dump rhashtable and encap and decap flows
- H5 32
- CDN
- Kotlin语法(七)
- h5 33
- (117)BitMask蓝图变量