CCPry JS类库 代码
2024-05-06 14:13:07
供稿:网友
代码如下:
function CCPry(){
//
// 判断浏览器类型
//
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
};
//
//根据元素ID返回DOM对象
//
this.$Id=function(id){
return document.getElementById(id);
};
//
//根据元素ID返回DOM对象
//
this.Id=function(id){
var DomObjId=this.$Id(id);
if(!DomObjId){ throw new Error("No Object!");}
//返回或设置对象的innerHTML属性
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!");};
};
//返回或设置对象的innerText属性
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!");};
};
//返回或设置对象的value属性
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;
};
//
//根据元素Name返回DOM对象
//
this.$Name=function(name){
return document.getElementsByName(name);
};
//
//判断字符串是否为空或者null
//
this.IsNullOrEmpty=function( str ) {
if(str==null){
return true;
}
else{
if(str.length<=0){
return true;
}
}
return false;
};
//
//判断字符串是否为空
//
this.IsEmpty=function( str ) {
if(str.length<=0){
return true;
}
return false;
};
//
//判断字符串是否null
//
this.IsNull=function( str ) {
if(str==null){
return true;
}
return false;
};
//
//判断是否是函数
//
this.IsFunction=function( fn ) {
return typeof(fn)=="function";
};
//
//判断是否是对象
//
this.IsObject=function( fn ) {
return typeof(fn)=="object";
};
//
//判断是否是字符串
//
this.IsString=function( fn ) {
return typeof(fn)=="string";
};
//
//判断是否是数字型
//
this.IsNumber=function( fn ) {
return typeof(fn)=="number";
};
//
//判断是否是布尔型
//
this.IsBoolean=function( fn ) {
return typeof(fn)=="boolean";
};
//
//判断是否未定义
//
this.IsUndefined=function( fn ) {