function $(v){
return document.getElementById(v); 
}function $n(n, index){
var es = document.getElementsByName(n);
if (typeof(index) == 'undefined') {
index = 0;
}
if (index >= es.length) {
index = es.length - 1;
}
return es[index];
}function Ajax(url, params, callback, method) {

this.createHttpRequest = function() {
if (window.ActiveXObject) {
try {
return new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
} else {
return new XMLHttpRequest();
}
}
this.url = url;
this.params = params;
this.callback = callback;
this.method = method == null? "post" : method;
this.xmlHttp = this.createHttpRequest();

window.myAjax = this;
this.doRequest = function() {
var query = "";
for (var param in this.params) {
if (query != "") {
query += "&";
}
query += param + "=" + this.params[param];
} if (this.method == "post") {
this.xmlHttp.open(this.method, this.url, true);
this.xmlHttp.onreadystatechange = this.stateChanged;
this.xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
this.xmlHttp.send(query);
} else {
if (query.length>0) this.url += "?" + query;
try {
this.xmlHttp.open(this.method, this.url);
} catch (err) {}
this.xmlHttp.setRequestHeader('Content-Type','text/html; charset=gbk');
this.xmlHttp.setRequestHeader('Cache-Control', 'no-cache');
this.xmlHttp.setRequestHeader('X-Powered-KW', '1');
this.xmlHttp.onreadystatechange = this.stateChanged;
this.xmlHttp.send(null);
//return this.xmlHttp.responseBody;
}
};
this.stateChanged = function() {
if (myAjax.xmlHttp.readyState==4 || myAjax.xmlHttp.readyState=="complete") {
var data = myAjax.xmlHttp.responseText;
myAjax.callback(data);
}
};

}function outputContent(uri){
$("text_area").innerHTML = "<font style='color:blue;font-size:24px'>正在加载章节内容,请稍后...</font>";
var fullurl = "";
var defaulturl = "http://"+document.domain+"/";
var s = Math.round(Math.random()*2);
if (s == 0)
{
defaulturl += "ebak"+uri;
}
else
{
defaulturl += "egbk"+uri;
}

fullurl = defaulturl;
var ajax =new Ajax(fullurl, null, showContent, "get");
ajax.doRequest();
}function showContent(message) {
if (message.length >0) {
message = message.replace(/ /g, "&nbsp;")
message = message.replace(/\n/g, "<br />");
}
else
{
message = '<font style="color:red;font-size:24px">获取内容失败,请<a href="#" onclick="window.location.reload();">点此刷新</a>本页面重新获取...</font>'
}
$("text_area").innerHTML = message;
LoadSet();
//alert(message);
}

解决方案 »

  1.   

    代码缩进弄好了,能容易理解很多。把代码放到[code][/code]标签中,你多花10秒钟,别人读你的代码能少用xx分钟,愿意看看,试试的人会多几倍。
      

  2.   

    代码缩进弄好了,能容易理解很多。把代码放到[code][/code]标签中,你多花10秒钟,别人读你的代码能少用xx分钟,愿意看看,试试的人会多几倍。
    [/Quote]关键是我不会JAVASCRIPT呀,所以才全贴出来的
      

  3.   


    <script language="javascript" type="text/javascript">
    function $(v){
     return document.getElementById(v);  
    }function $n(n, index){
     var es = document.getElementsByName(n);
     if (typeof(index) == 'undefined') {
     index = 0;
     }
     if (index >= es.length) {
     index = es.length - 1;
     }
     return es[index];
    }function Ajax(url, params, callback, method) {
     
    this.createHttpRequest = function() {
     if (window.ActiveXObject) {
     try {
     return new ActiveXObject('Msxml2.XMLHTTP');
     } catch (e) {
     return new ActiveXObject("Microsoft.XMLHTTP");
     }
     } else {
     return new XMLHttpRequest();
     }
     }
     this.url = url;
     this.params = params;
     this.callback = callback;
     this.method = method == null? "post" : method;
     this.xmlHttp = this.createHttpRequest();
     
    window.myAjax = this;
     this.doRequest = function() {
     var query = "";
     for (var param in this.params) {
     if (query != "") {
     query += "&";
     }
     query += param + "=" + this.params[param];
     } if (this.method == "post") {
     this.xmlHttp.open(this.method, this.url, true);
     this.xmlHttp.onreadystatechange = this.stateChanged;
     this.xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
     this.xmlHttp.send(query);
     } else {
     if (query.length>0) this.url += "?" + query;
     try {
     this.xmlHttp.open(this.method, this.url);
     } catch (err) {}
     this.xmlHttp.setRequestHeader('Content-Type','text/html; charset=gbk');
     this.xmlHttp.setRequestHeader('Cache-Control', 'no-cache');
     this.xmlHttp.setRequestHeader('X-Powered-KW', '1');
     this.xmlHttp.onreadystatechange = this.stateChanged;
     this.xmlHttp.send(null);
     //return this.xmlHttp.responseBody;
     }
     };
     this.stateChanged = function() {
     if (myAjax.xmlHttp.readyState==4 || myAjax.xmlHttp.readyState=="complete") {
     var data = myAjax.xmlHttp.responseText;
     myAjax.callback(data);
     }
     };
     
    }function outputContent(uri){
     $("text_area").innerHTML = "<font style='color:blue;font-size:24px'>正在加载章节内容,请稍后...</font>";
     var fullurl = "";
     var defaulturl = "http://"+document.domain+"/"; 
    var s = Math.round(Math.random()*2);
     if (s == 0)
     {
     defaulturl += "ebak"+uri;
     }
     else
     {
     defaulturl += "egbk"+uri;
     }
     
    fullurl = defaulturl;
     var ajax =new Ajax(fullurl, null, showContent, "get");
     ajax.doRequest();
    }function showContent(message) {
     if (message.length >0) { 
    message = message.replace(/ /g, "&nbsp;")
      message = message.replace(/\n/g, "<br />");
     }
     else
     {
     message = '<font style="color:red;font-size:24px">获取内容失败,请<a href="#" onclick="window.location.reload();">点此刷新</a>本页面重新获取...</font>'
     }
     $("text_area").innerHTML = message;
     LoadSet();
     //alert(message);
    }
    </script>