Copy Code code as follows:
function Ccpry () {
//
Determine browser type
//
This. Browser ={
"Ismozilla":(typeof document.implementation!= ' undefined ') && (typeof Document.implementation.createDocument!= ' undefined ') && (typeof htmldocument!= ' undefined '),
"Isie": Window. ActiveXObject? True:false,
"Isfirefox": Navigator.userAgent.toLowerCase (). IndexOf ("Firefox")!=-1,
"Isopera": Navigator.userAgent.toLowerCase (). IndexOf ("opera")!=-1
};
//
Returns a DOM object based on the element ID
//
this. $Id =function (Id) {
return document.getElementById (ID);
};
//
Returns a DOM object based on the element ID
//
This. Id=function (ID) {
var domobjid=this. $Id (ID);
if (! Domobjid) {throw new Error ("No object!");}
Returns or sets the innerHTML property of an object
This. Html=function (HTML) {
if (!this. Isundefined (domobjid.innerhtml))
{
if (!this. IsNull (HTML)) {
domobjid.innerhtml=html;
}
else{return domobjid.innerhtml};
}
else{throw new Error ("Object does not support the property innerhtml!");
};
Returns or sets the InnerText property of an object
This. Text=function (text) {
if (!this. Isundefined (Domobjid.innertext))
{
if (!this. IsNull (text)) {
Domobjid.innertext=text;
}
else{return Domobjid.innertext};
}
else{throw new Error ("Object does not support the property innertext!");
};
Returns or sets the Value property of an object
This. Val=function (val) {
if (!this. Isundefined (Domobjid.value))
{
if (!this. IsNull (val)) {
Domobjid.value=val;
}
else{return Domobjid.value};
}
else{throw new Error ("Object does not support the property value!");
}
return this;
};
//
Returns a DOM object based on the element name
//
this. $Name =function (Name) {
return Document.getelementsbyname (name);
};
//
Determines whether a string is empty or null
//
This. Isnullorempty=function (str) {
if (str==null) {
return true;
}
else{
if (str.length<=0) {
return true;
}
}
return false;
};
//
Determines whether a string is empty
//
This. Isempty=function (str) {
if (str.length<=0) {
return true;
}
return false;
};
//
To determine whether a string is null
//
This. Isnull=function (str) {
if (str==null) {
return true;
}
return false;
};
//
Judge whether it is a function
//
This. Isfunction=function (FN) {
Return typeof (fn) = = "function";
};
//
Judge whether it is an object
//
This. Isobject=function (FN) {
Return typeof (fn) = = "Object";
};
//
Judge whether it is a string
//
This. Isstring=function (FN) {
Return typeof (fn) = = "string";
};
//
Judge whether it is a digital type
//
This. Isnumber=function (FN) {
Return typeof (fn) = = "Number";
};
//
To determine if it is a Boolean type
//
This. Isboolean=function (FN) {
Return typeof (fn) = = "Boolean";
};
//
Determine if not defined
//
This. Isundefined=function (FN) {
Return typeof (fn) = = "undefined";
};
//
Determine if the date type
//
This. Isdate=function (FN) {
return fn.constructor==date;
};
//
Back to Ajax objects
//
This. Ajax=function (s) {
Constructing XMLHttpRequest Objects
Getxmlhttprequest=function () {
var XMLHttpRequest;
if (window. XMLHttpRequest) {XMLHttpRequest = new XMLHttpRequest ();}
else if (window. ActiveXObject) {
try {XMLHttpRequest = new ActiveXObject ("Msxml2.xmlhttp");}
catch (e) {XMLHttpRequest = new ActiveXObject ("Microsoft.XMLHTTP");}
}
if (!xmlhttprequest) {
Alert ("Create XMLHttpRequest object Failed");
return null;
}
return XMLHttpRequest;
};
Default AJAX Configuration
ajaxsettings={
URL: "/ajax/processajax.ashx",
Method: "POST",
timeout:0,
MimeType: "Application/x-www-form-urlencoded",
Async:true,
Data:null,
DataType: "HTML",
CharSet: "Utf-8",
Accepts: {
XML: "Application/xml, Text/xml",
HTML: "Text/html",
Script: "Text/javascript, Application/javascript",
JSON: "Application/json, Text/javascript",
Text: "Text/plain",
_default: "*/*"
},
<summary>
Call function at start of request
</summary>
Onstart:function () {
Start
},
<summary>
callback function after successful request
</summary>
<param name= "MSG" > Server return Data </param>
Onsuccess:function (msg) {
Success
},
<summary>
Operation Exception Call function
</summary>
<param name= "MSG" > Exception information </param>
Onexception:function (msg) {
exception
},
<summary>
Call the function after the request times out
</summary>
Ontimeout:function () {
Timeout
},
<summary>
Call function upon completion of request
</summary>
Oncomplate:function () {
Complate
}
};
if (this. IsObject (s)) {
/* Detect incoming objects * *
Ajaxsettings.url = (!this. isundefined (S.url) && this. Isstring (S.url))? S.url:ajaxsettings.url;
Ajaxsettings.method = (!this. isundefined (S.method) && this. Isstring (S.method))? S.method:ajaxsettings.method;
Ajaxsettings.timeout = (!this. isundefined (s.timeout) && this. Isnumber (s.timeout))? S.timeout:ajaxsettings.timeout;
Ajaxsettings.mimetype= (!this. isundefined (S.mimetype) && this. Isstring (S.mimetype))? S.mimetype:ajaxsettings.mimetype;
Ajaxsettings.async = (!this. isundefined (S.async) && this. Isboolean (S.async))? S.async:ajaxsettings.async;
Ajaxsettings.data = (!this. isundefined (S.data) && this. Isstring (S.data))? S.data:ajaxsettings.data;
Ajaxsettings.datatype = (!this. isundefined (S.datatype) && this. Isstring (S.datatype))? S.datatype:ajaxsettings.datatype;
Ajaxsettings.charset = (!this. isundefined (S.charset) && this. Isstring (S.charset))? S.charset:ajaxsettings.charset;
Ajaxsettings.onstart = (!this. isundefined (S.onstart) && this. Isfunction (S.onstart))? S.onstart:ajaxsettings.onstart;
Ajaxsettings.onsuccess = (!this. isundefined (s.onsuccess) && this. Isfunction (s.onsuccess))? s.onsuccess:ajaxsettings.onsuccess;
Ajaxsettings.onexception= (!this. isundefined (s.onexception) &&this. Isfunction (s.onexception))? s.onexception:ajaxsettings.onexception;
Ajaxsettings.ontimeout = (!this. isundefined (s.ontimeout) && this. Isfunction (s.ontimeout))? S.ontimeout:ajaxsettings.ontimeout;
Ajaxsettings.oncomplate= (!this. isundefined (s.oncomplate) && this. Isfunction (s.oncomplate))? S.oncomplate:ajaxsettings.oncomplate;
Assignment xmlhttp, passing in XMLHttpRequest object
var xmlhttp=getxmlhttprequest ();
var Requestdone=false;
Try
{
Determine what parameters Xmlhttp.send () needs to pass in according to the post or Get method
if (Ajaxsettings.data && ajaxSettings.method.toUpperCase () = = "Get") {
Ajaxsettings.url + = (AjaxSettings.url.match (/\?/)? "&": "?" + Ajaxsettings.data;
Ajaxsettings.data = null;
}
Xmlhttp.open (Ajaxsettings.method,ajaxsettings.url,ajaxsettings.async);
Xmlhttp.setrequestheader ("Content-type", Ajaxsettings.mimetype);
Xmlhttp.setrequestheader ("X-requested-with", "XMLHttpRequest"); Set the caption to indicate a XMLHttpRequest request
Xmlhttp.setrequestheader ("Accept", Ajaxsettings.datatype && ajaxsettings.accepts[ajaxsettings.datatype)? ajaxsettings.accepts[Ajaxsettings.datatype] + ", */*": Ajaxsettings.accepts._default);
if (ajaxsettings.timeout>0) {
var timer=settimeout (function () {requestdone=true;xmlhttp.abort ();},ajaxsettings.timeout);
}
var xmlreadystatechange=function ()
{
if (requestdone) {ajaxsettings.ontimeout ();}//timeout
else if (xmlhttp.readystate==4)//success
{
if (timer) {cleartimeout (timer); timer = null;}
if (xmlhttp.status==200 | | xmlhttp.status== "SUCCESS")
{
Switch (AjaxSettings.datatype.toLowerCase ())
{
Case "HTML":
Ajaxsettings.onsuccess (Xmlhttp.responsetext);
Break
Case "XML":
Ajaxsettings.onsuccess (Xmlhttp.responsexml);
Break
}
}
Ajaxsettings.oncomplate (); Complate
if (ajaxsettings.async&&xmlhttp) {xmlhttp=null;}
}
Else{ajaxsettings.onstart ();}//start
}
Xmlhttp.onreadystatechange=xmlreadystatechange;
Xmlhttp.send (Ajaxsettings.data);
if (!ajaxsettings.async) {xmlreadystatechange (); xmlhttp=null;}
}
catch (e) {
Ajaxsettings.onexception (E.message); exception
}
}
return this;
}
//
Split a JSON object and compose a string with a specific symbolic connection
//
This. Splitjson=function (jsonobj,splitsign) {
var jsonstr= ', Signlastindex;
For (Jo in Jsonobj)
{
Jsonstr + = (jo + "=" + Jsonobj[jo] + splitsign);
}
Signlastindex=jsonstr.lastindexof (splitsign);
if (signlastindex!=-1) {
Jsonstr=jsonstr.substring (0,signlastindex);
}
return jsonstr;
}
//
JS thumbnail image
//
This. Drawimage=function (imgd,iwidth,iheight) {
var Flag=false;
var image=new image ();
IMAGE.SRC=IMGD.SRC;
if (image.width>0 && image.height>0)
{
Flag=true;
if (image.width/image.height>= iwidth/iheight)
{
if (image.width>iwidth)
{
Imgd.width=iwidth;
imgd.height= (image.height*iwidth)/image.width;
}
Else
{
Imgd.width=image.width;
Imgd.height=image.height;
}
}
Else
{
if (image.height>iheight)
{
Imgd.height=iheight;
Imgd.width= (image.width*iheight)/image.height;
}
Else
{
Imgd.width=image.width;
Imgd.height=image.height;
}
}
}
}
//
Intercept string contains Chinese processing
//
This. Substring=function (str, len, Hasdot) {
var newlength = 0;
var newstr = "";
var chineseregex =/[^\x00-\xff]/g;
var Singlechar = "";
var strlength = str.replace (Chineseregex, "* *"). Length;
for (var i = 0;i < strlength;i++)
{
Singlechar = Str.charat (i). toString ();
if (Singlechar.match (Chineseregex)!= null)
{
Newlength + 2;
}
Else
{
newlength++;
}
if (Newlength > Len)
{
Break
}
Newstr + = Singlechar;
}
if (Hasdot && strlength > Len)
{
Newstr + = "";
}
return newstr;
}
//
Replace All
//
This. Replaceall=function (str,oldstring,newstring) {
Return Str.replace (New RegExp (oldstring, "GM"), newstring);
},
//
Get URL parameter, invalid return undfined
//
This. Requestquerystring=function (URL) {
var qindex=url.indexof ('? ');
var queryobj={};
if (qindex!=-1) {
var querystr=url.substring (qindex+1,url.length);
if (Querystr.indexof (' & ')!=-1) {
var arrquery = new Array ();
Arrquery=querystr.split (' & ');
For (Arrstr in Arrquery) {
Paramkey=arrquery[arrstr].substring (0,arrquery[arrstr].indexof ("=")). toLowerCase ();
Paramvalue=arrquery[arrstr].substring (arrquery[arrstr].indexof ("=") +1,arrquery[arrstr].length);
Queryobj[paramkey]=paramvalue
}
}
else{
Paramkey=querystr.substring (0,querystr.indexof ("=")). toLowerCase ();
Paramvalue=querystr.substring (querystr.indexof ("=") +1,querystr.length);
Queryobj[paramkey]=paramvalue;
}
}
return queryobj;
}
}
window. $CC =new ccpry ();