1 Star 0 Fork 0

染青/icedog.javascript.test

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index-routes.html 3.25 KB
一键复制 编辑 原始数据 按行查看 历史
染青 提交于 2018-01-02 01:21 +08:00 . 添加sammy demo
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<script src="../../js/lib/jquery-v3.0.0/jquery.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/lib/jquery-sammy-v0.7.6/sammy.js" type="text/javascript" charset="utf-8"></script>
<title>jquery.sammy</title>
</head>
<body>
<p>jquery.sammy <b>route</b></p>
<p>sammy的路由中verb的值为get的时候仅仅监听了<b> hash changes</b>,其余的post 、put、delete则只监听的表 单(form)的submit事件,因此ajax的请求不会触发路由
</p>
<p>对于同一路由只会绑定第一个,后续的不会触发</p>
<hr />
<a href="#/">#/</a>
<a href="#/hi-route">#/hi-route</a>
<a href="#/hi-get">#/hi-get</a>
<a href="#/color">#/color</a>
<a href="#/by-name/quirkey">#/by-name/quirkey</a>
<a href="#/child/a/b/c/d">#/child/a/b/c/d</a>
<div id="main1">
<p class="welcome"></p>
<p class="hello-world"></p>
<form action="#/post/form" method="PUT">
<label>First Name</label><br />
<input type="text" name="first_name" />
<input type="submit" value="Submit" />
</form>
</div>
<div id="main2">
</div>
<script type="text/javascript">
//$.sammy 和 Sammy 等价 ,默认使用的app节点为body节点
var app = $.sammy('#main1', function(contextSammy) {
var sam = contextSammy;
//context 和 this 相等
debugger;
//http://sammyjs.org/docs/routes
//this.get, post, put, delete(del)
//#/, test/path/, #/my_path/:var
this.get('#/', function(context, nextRoute) {
debugger;
$('.welcome').text('Welcome! by $.sammy');
$.get('data/hello-world.html', function(data, status, promise) {
debugger;
// save the data somewhere
$(data).appendTo('.hello-world');
sam.log('step one is loaded;');
nextRoute();
});
}, function(context, nextRoute) {
debugger;
$.get('data/hello-world.html', function(data, status, promise) {
debugger;
// save the data somewhere
$(data).css({
'font-size': '30px',
'color': 'green'
}).appendTo('.hello-world');
sam.log('step two is loaded;');
nextRoute();
});
}, function() {
sam.log('all data is loaded;');
});
// route(verb, path, callback)
this.route('get', '#/hi-route', function(context, nextRoute) {
alert('hi by this.route');
});
// verb(path, callback)
this.get('#/hi-get', function(context, nextRoute) {
alert('hi by this.get');
});
this.put('#/post/form', function() {
alert('put to #/post/form');
return false;
});
this.get(/#\/color/, function() {
alert('start with color request');
});
this.get('#/by-name/:name', function() {
alert(this.params['name']);
});
this.get(/\#\/child\/(.*)/, function() {
alert(this.params['splat']);
});
}).run('#/');
//如果有使用到dom则应该在此运行app
// $(function () {
// app.run('#/');
// });
/*
var app = Sammy('#main2', function() {
this.get('#/', function() {
$('#main2').text('Welcome! by Sammy');
});
}).run('#/');
*/
</script>
</body>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/dhclly/icedog.javascript.test.git
git@gitee.com:dhclly/icedog.javascript.test.git
dhclly
icedog.javascript.test
icedog.javascript.test
master

搜索帮助