标签:
var publish = { //该模块初始化入口 init : function(){ this.renderData(param); this.initListeners(); }, //内部所用的函数 renderData : function(param){ //渲染数据。。 }, //统一绑定监听器 initListeners : function(){ $(document.body).delegates({ ‘.btn‘ : function(){ //点击事件 }, ‘.btn2‘ : function(){ //点击事件2 }, ‘.checkbox‘ : { ‘change‘ : function(){ //change事件 } } }); } }
//以配置的方式代理事件 $.fn.delegates = function(configs) { el = $(this[0]); for (var name in configs) { var value = configs[name]; if (typeof value == ‘function‘) { var obj = {}; obj.click = value; value = obj; }; for (var type in value) { el.delegate(name, type, value[type]); } } return this; }
<script src="static/js/tpl/head.js"></script> <div id="header"> <script src="static/js/includeHead.js"></script> </div>
function includeHead(){ var header = document.getElementById(‘header‘); var compileHead = Handlebars.templates[‘head‘]; var head = compileHead({}); document.write(head); } includeHead();
window.onhashchange = this.loadPage;
‘.next‘ : function(){ location.href = ‘#step2‘; }
Handlebars.registerHelper(‘param‘, function(key, options){ var url = location.href.replace(/^[^?=]*\?/ig, ‘‘).split(‘#‘)[0]; var json = {}; url.replace(/(^|&)([^&=]+)=([^&]*)/g, function (a, b, key , value){ try { key = decodeURIComponent(key); } catch(e) {} try { value = decodeURIComponent(value); } catch(e) {} if (!(key in json)) { json[key] = /\[\]$/.test(key) ? [value] : value; } else if (json[key] instanceof Array) { json[key].push(value); } else { json[key] = [json[key], value]; } }); return key ? json[key] : json; });
<a href="detail.html?id={{param id}}">设备详细信息</a>
标签:
原文地址:http://www.cnblogs.com/lvdabao/p/4204858.html