单页开发

html 何求龙

function Router() {
	this.routes = {};
	this.currentUrl = '';
}
Router.prototype.route = function(path, callback) { //route 存储路由更新时的回调到回调数组routes中,回调函数将负责对页面的更新
	this.routes[path] = callback || function() {};
};
Router.prototype.refresh = function() { //refresh 执行当前url对应的回调函数,更新页面
	this.currentUrl = location.hash.slice(1) || '/';
	this.routes[this.currentUrl]();
};
Router.prototype.init = function() { //init 监听浏览器 url hash 更新事件
	window.addEventListener('load', this.refresh.bind(this), false);
	window.addEventListener('hashchange', this.refresh.bind(this), false);
}
window.Router = new Router();
window.Router.init();

var box = document.querySelector("#show-all");//获取设置好的空盒子对象
//通过路径判断要访问那个页面,就把那个页面的内容放到设置好的空盒子里面
Router.route('/', function() {
	box.innerHTML = document.getElementById("login-page").innerHTML;
})
Router.route('enroll-page', function() {
	box.innerHTML = document.getElementById("enroll-page").innerHTML;
})
Router.route('forget-password', function() {
	box.innerHTML = document.getElementById("forget-password").innerHTML;
})
Router.route('forget-password-Email', function() {
	box.innerHTML = document.getElementById("forget-password-Email").innerHTML;
})
Router.route('forget-password-phone', function() {
	box.innerHTML = document.getElementById("forget-password-phone").innerHTML;
})

还能输出{{restrictNumber}}个字符  
  • {{reply.author}}

    {{CommonUtil.formateDate(reply.ac_CommentDate).shortTime}}
  • 回复了{{Comments.author}} :