Copy codeThe Code is as follows:
Function CCPry (){
//
// Determine the 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
};
//
// Return the DOM object based on the element ID
//
This. $ Id = function (id ){
Return document. getElementById (id );
};
//
// Return the DOM object based on the element ID
//
This. Id = function (id ){
Var DomObjId = this. $ Id (id );
If (! DomObjId) {throw new Error ("No Object! ");}
// Return or set the innerHTML attribute of the 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! ");};
};
// Return or set the innerText attribute of the 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! ");};
};
// Return or set the value attribute of the 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;
};
//
// Return the DOM object based on the element Name
//
This. $ Name = function (name ){
Return document. getElementsByName (name );
};
//
// Judge whether the string is null or null
//
This. IsNullOrEmpty = function (str ){
If (str = null ){
Return true;
}
Else {
If (str. length <= 0 ){
Return true;
}
}
Return false;
};
//
// Judge whether the string is null
//
This. IsEmpty = function (str ){
If (str. length <= 0 ){
Return true;
}
Return false;
};
//
// Judge whether the string is null
//
This. IsNull = function (str ){
If (str = null ){
Return true;
}
Return false;
};
//
// Determine whether it is a function
//
This. IsFunction = function (fn ){
Return typeof (fn) = "function ";
};
//
// Determine whether it is an object
//
This. IsObject = function (fn ){
Return typeof (fn) = "object ";
};
//
// Determine whether it is a string
//
This. IsString = function (fn ){
Return typeof (fn) = "string ";
};
//
// Determine whether the data type is digital
//
This. IsNumber = function (fn ){
Return typeof (fn) = "number ";
};
//
// Determine whether it is a Boolean Type
//
This. IsBoolean = function (fn ){
Return typeof (fn) = "boolean ";
};
//
// Determine whether or not it is undefined
//
This. IsUndefined = function (fn ){
Return typeof (fn) = "undefined ";
};
//
// Determine whether it is a date type
//
This. IsDate = function (fn ){
Return fn. constructor = Date;
};
//
// Return the Ajax object
//
This. Ajax = function (s ){
// Construct the XMLHttpRequest object
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 ("failed to create XMLHttpRequest object ");
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 the function at the request start
/// </Summary>
OnStart: function (){
// Start
},
/// <Summary>
/// Callback function after successful request
/// </Summary>
/// <Param name = "msg"> data returned by the server </param>
OnSuccess: function (msg ){
// Success
},
/// <Summary>
/// Call a function with an operation exception
/// </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 the function after the request is complete
/// </Summary>
OnComplate: function (){
// Complate
}
};
If (this. IsObject (s )){
/* Check the input object */
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;
// Assign a value to xmlhttp and pass in the XMLHttpRequest object
Var xmlhttp = GetXmlHttpRequest ();
Var requestDone = false;
Try
{
// Determine the parameters to be passed in xmlhttp. send () based on 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"); // you can specify the title of an 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 the JSON object and connect it with a specific symbol to form a string
//
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;
}
//
// Scaling down JS Images
//
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;
}
}
}
}
//
// Extract a string that contains Chinese characters for 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 );
},
//
// Obtain the URL parameter. If the URL parameter is invalid, undfined is returned.
//
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 ();