[color=red][b]1.share.js[/b][/color]
function MyAjax(url) {
this.url = url;
this.xmlHttp = {};
};
MyAjax.prototype.createXMLHttpRequest = function() {
if (window.XMLHttpRequest) {
this.xmlHttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
this.xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
};
MyAjax.prototype.sendPostRequest = function(queryString, handle) {
this.createXMLHttpRequest();
this.xmlHttp.open("POST", this.url, true);
this.xmlHttp.onreadystatechange = handle;
this.xmlHttp.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded; charset=UTF-8");
this.xmlHttp.send(queryString);
};
MyAjax.prototype.sendPostRequest = function(queryString, url, winnercallback) {
this.createXMLHttpRequest();
this.xmlHttp.open("POST", url, true);
this.xmlHttp.onreadystatechange = winnercallback;
this.xmlHttp.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded; charset=UTF-8");
this.xmlHttp.send(queryString);
};
[color=darkred]2.类重写方法基础类[/color]
Ext = {};//Ext = {};
Ext.javapackage = function() {
var a = arguments, o = null, i, j, d, rt;
for (i = 0;i < a.length; ++i) {
d = a[i].split(".");
rt = d[0];
eval('if (typeof ' + rt + ' == "undefined"){' + rt + ' = {};} o = '
+ rt + ';');
for (j = 1;j < d.length; ++j) {
o[d[j]] = o[d[j]] || {};
o = o[d[j]];
}
}
};
Ext.apply = function(o, c, defaults){
if(defaults){
// no "this" reference for friendly out of scope calls
Ext.apply(o, defaults);
}
if(o && c && typeof c == 'object'){
for(var p in c){
o[p] = c[p];
}
}
return o;
};
/*====================Array====================*/
Ext.apply(Array.prototype, {
indexOf : function(o){
for (var i = 0, len = this.length; i < len; i++){
if(this[i] == o) return i;
}
return -1;
},
remove : function(o){
var index = this.indexOf(o);
if(index != -1){
this.splice(index, 1);
}
}
});
/*====================String====================*/
Ext.apply(String.prototype, {
trim : function() {
return this.replace(/(\s*$)/g, "").replace(/(^\s*)/g, "");//先去掉结尾空格,再去掉开头空格。
},
format : function() {
var args = Array.prototype.slice.call(arguments, 0);
return this.replace(/\{(\d+)\}/g, function(m, i){return args[i];});
},
formatAry : function() {
var a=arguments;
if(typeof arguments[0]=="object"){
a=arguments[0];
}
var args = Array.prototype.slice.call(a, 0);
return this.replace(/\{(\d+)\}/g, function(m, i){return args[i];});
},
zero2int: function() {
if(parseInt(this)!=0)return parseInt(this);
return parseInt(this.replace(/^0/,""));
},
clearZero: function(){
var t=""+this;
if(t[0]=="0"){
t=this.replace(/^0/,"");
t=clearZear(t);
}
return t;
},
string2int: function(){//前面n个0的字符串变数字
var t=""+this;
while((/^0/.test(t)))t=t.replace(/^0/,"");
return /^\d+$/.test(t)?parseInt(t):t;
}
});
/*====================Function====================*/
Ext.apply(Function.prototype, {
createCallback : function(/*args...*/){
var args = arguments;
var method = this;
return function() {
return method.apply(window, args);
};
},
createDelegate : function(obj, args, appendArgs){
var method = this;
return function() {
var callArgs = args || arguments;
if(appendArgs === true){
callArgs = Array.prototype.slice.call(arguments, 0);
callArgs = callArgs.concat(args);
}else if(typeof appendArgs == "number"){
callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
var applyArgs = [appendArgs, 0].concat(args); // create method call params
Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
}
return method.apply(obj || window, callArgs);
};
},
defer : function(millis, obj, args, appendArgs){
var fn = this.createDelegate(obj, args, appendArgs);
if(millis){
return setTimeout(fn, millis);
}
fn();
return 0;
},
createSequence : function(fcn, scope){
if(typeof fcn != "function"){
return this;
}
var method = this;
return function() {
var retval = method.apply(this || window, arguments);
fcn.apply(scope || this || window, arguments);
return retval;
};
},
createInterceptor : function(fcn, scope){
if(typeof fcn != "function"){
return this;
}
var method = this;
return function() {
fcn.target = this;
fcn.method = method;
if(fcn.apply(scope || this || window, arguments) === false){
return;
}
return method.apply(this || window, arguments);
};
}
});
[color=red]3.调用
jsp页面中[/color]
<script>
(function kaijiangxinxiList(){
var a = new MyAjax();
a.sendPostRequest(null,kaijiangxinxiUrl, getCallback.createDelegate(a));
}())
</script>
[color=red]4.返回处理[/color]
function getKaijiangxinxiCallback() {
var xmlHttp = this.xmlHttp;
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
var json = eval("(" + xmlHttp.responseText + ")");
//alert("items.length="+json.items.length);
var s="";
for(var i=0;i<json.items.length;i++){//循环开始
s+="<div class=\"kaijiangxinxi_list_one\" onmouseout=\"this.className='kaijiangxinxi_list_one'\" onmouseover=\"this.className='kaijiangxinxi_list_two'\">";
s+="<div class=\"kaijiangdetail\">";
s+="<div class=\"kaijiangmessage\">";
function MyAjax(url) {
this.url = url;
this.xmlHttp = {};
};
MyAjax.prototype.createXMLHttpRequest = function() {
if (window.XMLHttpRequest) {
this.xmlHttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
this.xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
};
MyAjax.prototype.sendPostRequest = function(queryString, handle) {
this.createXMLHttpRequest();
this.xmlHttp.open("POST", this.url, true);
this.xmlHttp.onreadystatechange = handle;
this.xmlHttp.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded; charset=UTF-8");
this.xmlHttp.send(queryString);
};
MyAjax.prototype.sendPostRequest = function(queryString, url, winnercallback) {
this.createXMLHttpRequest();
this.xmlHttp.open("POST", url, true);
this.xmlHttp.onreadystatechange = winnercallback;
this.xmlHttp.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded; charset=UTF-8");
this.xmlHttp.send(queryString);
};
[color=darkred]2.类重写方法基础类[/color]
Ext = {};//Ext = {};
Ext.javapackage = function() {
var a = arguments, o = null, i, j, d, rt;
for (i = 0;i < a.length; ++i) {
d = a[i].split(".");
rt = d[0];
eval('if (typeof ' + rt + ' == "undefined"){' + rt + ' = {};} o = '
+ rt + ';');
for (j = 1;j < d.length; ++j) {
o[d[j]] = o[d[j]] || {};
o = o[d[j]];
}
}
};
Ext.apply = function(o, c, defaults){
if(defaults){
// no "this" reference for friendly out of scope calls
Ext.apply(o, defaults);
}
if(o && c && typeof c == 'object'){
for(var p in c){
o[p] = c[p];
}
}
return o;
};
/*====================Array====================*/
Ext.apply(Array.prototype, {
indexOf : function(o){
for (var i = 0, len = this.length; i < len; i++){
if(this[i] == o) return i;
}
return -1;
},
remove : function(o){
var index = this.indexOf(o);
if(index != -1){
this.splice(index, 1);
}
}
});
/*====================String====================*/
Ext.apply(String.prototype, {
trim : function() {
return this.replace(/(\s*$)/g, "").replace(/(^\s*)/g, "");//先去掉结尾空格,再去掉开头空格。
},
format : function() {
var args = Array.prototype.slice.call(arguments, 0);
return this.replace(/\{(\d+)\}/g, function(m, i){return args[i];});
},
formatAry : function() {
var a=arguments;
if(typeof arguments[0]=="object"){
a=arguments[0];
}
var args = Array.prototype.slice.call(a, 0);
return this.replace(/\{(\d+)\}/g, function(m, i){return args[i];});
},
zero2int: function() {
if(parseInt(this)!=0)return parseInt(this);
return parseInt(this.replace(/^0/,""));
},
clearZero: function(){
var t=""+this;
if(t[0]=="0"){
t=this.replace(/^0/,"");
t=clearZear(t);
}
return t;
},
string2int: function(){//前面n个0的字符串变数字
var t=""+this;
while((/^0/.test(t)))t=t.replace(/^0/,"");
return /^\d+$/.test(t)?parseInt(t):t;
}
});
/*====================Function====================*/
Ext.apply(Function.prototype, {
createCallback : function(/*args...*/){
var args = arguments;
var method = this;
return function() {
return method.apply(window, args);
};
},
createDelegate : function(obj, args, appendArgs){
var method = this;
return function() {
var callArgs = args || arguments;
if(appendArgs === true){
callArgs = Array.prototype.slice.call(arguments, 0);
callArgs = callArgs.concat(args);
}else if(typeof appendArgs == "number"){
callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
var applyArgs = [appendArgs, 0].concat(args); // create method call params
Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
}
return method.apply(obj || window, callArgs);
};
},
defer : function(millis, obj, args, appendArgs){
var fn = this.createDelegate(obj, args, appendArgs);
if(millis){
return setTimeout(fn, millis);
}
fn();
return 0;
},
createSequence : function(fcn, scope){
if(typeof fcn != "function"){
return this;
}
var method = this;
return function() {
var retval = method.apply(this || window, arguments);
fcn.apply(scope || this || window, arguments);
return retval;
};
},
createInterceptor : function(fcn, scope){
if(typeof fcn != "function"){
return this;
}
var method = this;
return function() {
fcn.target = this;
fcn.method = method;
if(fcn.apply(scope || this || window, arguments) === false){
return;
}
return method.apply(this || window, arguments);
};
}
});
[color=red]3.调用
jsp页面中[/color]
<script>
(function kaijiangxinxiList(){
var a = new MyAjax();
a.sendPostRequest(null,kaijiangxinxiUrl, getCallback.createDelegate(a));
}())
</script>
[color=red]4.返回处理[/color]
function getKaijiangxinxiCallback() {
var xmlHttp = this.xmlHttp;
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
var json = eval("(" + xmlHttp.responseText + ")");
//alert("items.length="+json.items.length);
var s="";
for(var i=0;i<json.items.length;i++){//循环开始
s+="<div class=\"kaijiangxinxi_list_one\" onmouseout=\"this.className='kaijiangxinxi_list_one'\" onmouseover=\"this.className='kaijiangxinxi_list_two'\">";
s+="<div class=\"kaijiangdetail\">";
s+="<div class=\"kaijiangmessage\">";