// 适配框架
// 两个框架为相似框架
window.A = A =jQuery
// 异类框架
var A = A || {};
A.g = function(id) {
return document.getElementById(id);
}
A.on = function(id, type, fn) {
var dom = typeof id == 'string' ? this.g(id) : id;
if (dom.addEventListener) {
dom.addEventListener(type, fn, false);
} else if (dom.attachEvent) {
dom.attackEvent('on' + type, fn);
} else {
dom['on' + type] = fn;
}
}
A.on(window, 'load', function() {
A.on('mybutton', 'click', function() {
......
})
})
// 适配器
A.g = function(id) {
return $(id).get(0);
}
A.on = function(id, type, fn) {
var dom = typeof id == 'string' ? $('#' + id) : $(id);
dom.on(type, fn);
}
服务器端数据适配
function ajaxAdapter(data) {
return [data['key1'], data['key2'], data['key3']];
}
$.ajax({
url : 'someAdress.php',
success : function(data, status) {
if (data) {
doSomething(ajaxAdapter(data));
}
}
});