当前位置: 首页 > 工具软件 > Comment.js > 使用案例 >

comm.js

屈畅
2023-12-01

/*加载时显示加载loading*/ function doReload(){ document.getElementById("ReLoad").style.display = 'block'; document.getElementById("ReLoad").style.left=(Math.round((document.body.scrollWidth-300)/2)).toString()+"px"; } /*函数功能:判断浏览器类型*/ window["MzBrowser"]={};(function(){if(MzBrowser.platform)return;var ua = window.navigator.userAgent; MzBrowser.platform = window.navigator.platform; MzBrowser.firefox = ua.indexOf("Firefox")>0; MzBrowser.opera = typeof(window.opera)=="object"; MzBrowser.ie = !MzBrowser.opera && ua.indexOf("MSIE")>0; MzBrowser.mozilla = window.navigator.product == "Gecko"; MzBrowser.netscape= window.navigator.vendor=="Netscape"; MzBrowser.safari= ua.indexOf("Safari")>-1; if(MzBrowser.firefox) var re = /Firefox(/s|//)(/d+(/./d+)?)/; else if(MzBrowser.ie) var re = /MSIE( )(/d+(/./d+)?)/; else if(MzBrowser.opera) var re = /Opera(/s|//)(/d+(/./d+)?)/; else if(MzBrowser.netscape) var re = /Netscape(/s|//)(/d+(/./d+)?)/; else if(MzBrowser.safari) var re = /Version(//)(/d+(/./d+)?)/;else if(MzBrowser.mozilla) var re = /rv(/:)(/d+(/./d+)?)/;if("undefined"!=typeof(re)&&re.test(ua))MzBrowser.version = parseFloat(RegExp.$2);})(); /*是否是只包含汉字*/ function isChineseCharacter(argValue){var argValue=document.getElementById(argValue).value;var ptn=/^[/u4e00-/u9fa5]+$/;if(ptn.exec(argValue)){return true;}else{return false;}} /*是否是数字型*/ function isInt(argValue){var argValue=document.getElementById(argValue).value;var ptn=/^[0-9]+$/;if(ptn.exec(argValue)){return true; }else{return false; }} /*是否是浮点数(格式6.45)*/ function isFloat(argValue){var argValue=document.getElementById(argValue).value;var ptn=/^[0-9]+[.]{1}[0-9]{2}$/;if(ptn.exec(argValue)){return true;}else{return false; }} /*是否为空(true/false)*/ function isEmpty(argValue){var argValue=document.getElementById(argValue).value;if(""==argValue || argValue==null || argValue.length==0){return true; }else{return false; }} /*是否是手机号码*/ function isMobile(argValue){var ptn=/^(13|15|18){1}[0-9]{9}$/;if(ptn.exec(argValue)){return true; }else{return false; }} /*是否是电话号码*/ function isTelephone(argValue){var ptn=/^[0-9]{3,4}[-]{1}[0-9]{7,9}$/; if(ptn.exec(argValue)){return true;}else{return false; }} /*获取字符串的长度 */ function getLength(argValue){var ptn=/^[/x00-/xff]$/;return ptn.exec(argValue).length;} /*是否是电子邮件*/ function isEmail(argValue){var ptn=/^/w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*$/;if(ptn.exec(argValue)){return true;}else{return false;}} /*是否是URL*/ function isURL(argValue){var ptn=/^[a-zA-z]+[^/s]*$/;if(ptn.exec(argValue)){return true;}else{return false;}} /*是否是腾讯QQ*/ function isQQ(argValue){var ptn=/^[1-9][0-9]{4,}$/;if(ptn.exec(argValue)){return true;}else{return false;}} /*是否是邮政编码*/ function isZipcode(argValue){var ptn=/^[1-9]/d{5}(?!/d)$/;if(ptn.exec(argValue)){return true;}else{return false;}} /*是否是中国的身份证为15位或18位*/ function isIDCard(argValue){var ptn=/^/d{15}|/d{18}$/;if(ptn.exec(argValue)){return true;}else{return false;}} /*是否是IP*/ function isIp(argValue){var ptn=/^/d+/./d+/./d+/./d+$/;if(ptn.exec(argValue)){return true;}else{return false;}} /*只包含大/小字母*/ function isIgnoreChar(argValue){var ptn=/^[A-Za-z]+$/;if(ptn.exec(argValue)){return true;}else{return false;}} /*只包含大写字母*/ function isBigChar(argValue){var ptn=/^[A-Z]+$/;if(ptn.exec(argValue)){return true;}else{return false;}} /*只包含小写字母*/ function isSmallChar(argValue){var ptn=/^[a-z]+$/;if(ptn.exec(argValue)){return true;}else{return false;}} /*只包含字符和数字*/ function isCharAndDigit(argValue){var ptn=/^[A-Za-z0-9]+$/;if(ptn.exec(argValue)){return true;}else{return false;}} /*只包含字符下划线和数字*/ function isWord(argValue){var ptn=/^/w+$/;if(ptn.exec(argValue)){return true;}else{return false;}} /*是否包含非法字符*/ function isIllegalChar(argValue){var charLst=new Array("and "," and"," and ","or "," or"," or ","in "," in"," in ","like "," like"," like ","exec "," exec"," exec "," insert","insert "," insert "," select","select "," select "," delete","delete "," delete "," update","update "," update ","count "," count"," count ","chr "," chr"," chr ");for(var i=0;i");for(var i=0;i/ig,'</script>');text = text.replace(/]*>.*<//iframe>/ig,'');text = text.replace(/]+>.*<//iframe>/ig,'');text = text.replace(/]+>/ig,'');text = text.replace(/&/g, "&");text = text.replace(/"/g, """);text = text.replace(//g, ">");text = text.replace(/'/g, "’");text = text.replace(// /g," ");text = text.replace(//n/g,"
");text = text.replace(//t/g,"    "); return text;} /*是否是该范围(第一个参数是值,第二个是范围最小值,最大值是范围最大值)*/ function isBetween(val,lowVal,highVal){if ((val < lowVal) || (val > highVal)){return (false);}else{return (true);}} /*是否是闰年*/ function isLeapyear(year){if((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0)){return (true);}else{return (false);}} /*小数验证(字符串,位数)*/ function isFloat(theStr,decLen){var dot1st = theStr.indexOf('.');var dot2nd = theStr.lastIndexOf('.');if (isEmpty(theStr)) return (false);if (dot1st == -1){if (!isInt(theStr)) return (false);else return (true);}else if (dot1st != dot2nd) return (false);else if (dot1st == 0) return (false);else{var intPart = theStr.substring(0,dot1st);var decPart = theStr.substring(dot2nd+1,theStr.length);if (decPart.length > decLen) return (false);else if (!isInt(intPart) || !isInt(decPart)) return (false);else if (isEmpty(decPart)) return (false);else return (true);}} /*日期格式的验证(格式如:yyyy-MM-dd或yyyy-MM)*/ function isDate(d, dateLen){if(d.length < dateLen){if (dateLen == 10){alert("无效的日期格式!!!请输入YYYY/MM/DD的日期格式!");}if (dateLen == 7){alert("无效的日期格式!!!请输入YYYY/MM的日期格式!");}return false;}else{try{if (dateLen == 10) {var a = new Date(d);var d1 = a.getYear();var d2 = a.getMonth()+1;var d3 = a.getDate();if (d2 < 10) d2 = "0" + d2;if (d3 < 10) d3 = "0" + d3;var dd = d1 + "/" + d2 + "/" + d3;if (d!=dd){alert("日期" + d + "输入错误!!!!");return false;}}else if (dateLen == 7){var a = new Date(d + "/01");var d1 = a.getYear();var d2 = a.getMonth()+1;var d3 = a.getDate();if (d2 < 10) d2 = "0" + d2;if (d3 < 10) d3 = "0" + d3;var dd = d1 + "/" + d2;if (d!=dd){alert("日期" + d + "输入错误!!!!");return false;}}return true;}catch(e){if (dateLen == 10){alert("无效的日期格式!!!请输入YYYY/MM/DD的日期格式!");}if (dateLen == 7){alert("无效的日期格式!!!请输入YYYY/MM的日期格式!");}return false;}}}

 

 

 

 

 

 

 

 

 

function $getObj(id)
{
    return document.getElementById(id);
}

//去除字符串两边空格
function Trims(sInput) {
    var sInput=String(sInput);
    var sReturn;
    sReturn = sInput.replace(/(^/s*)|(/s*$)/g, "");
    return sReturn;
}

/*
转换成大写
参数:一个元素对象
*/
function toUpperCaseObj(obj)
{
    if(obj)
    {
       obj.value=String(obj.value).toUpperCase();
    }
}

/*
转换成大写
参数:一个元素名称
*/
function toUpperCaseTxt(txtElem)
{
    var obj=$getObj(txtElem);
    if(obj)
    {
        obj.value=String(obj.value).toUpperCase();
    }
}

/**
isValidDate: 用于判断一个字符串是否是日期格式的字符串
 
返回值:
true或false
 
参数:
DateString: 判断的字符串
Dilimeter : 日期的分隔符,缺省值为'-'
*/
function isValidDate(DateString , Dilimeter)
{
  if (DateString==null) return false;

  if (Dilimeter=='' || Dilimeter==null)
   Dilimeter = '-';
   
  var tempy='';
  var tempm='';
  var tempd='';
  
  var tempArray;
  
  if (DateString.length<8 && DateString.length>10)
   return false; 
   
  tempArray = DateString.split(Dilimeter);
  
  if (tempArray.length!=3)
   return false;
  if (tempArray[0].length==4)
   {
    tempy = tempArray[0];
    tempd = tempArray[2];
   }
  else
   {
    tempy = tempArray[2];
    tempd = tempArray[1];
   }
  tempm = tempArray[1];
  
  var tDateString = tempy + '/'+tempm + '/'+tempd+' 8:0:0';//加八小时是因为我们处于东八区
  
  var tempDate = new Date(tDateString);
  if (isNaN(tempDate))
   return false;
  if (((tempDate.getUTCFullYear()).toString()==tempy) && (tempDate.getMonth()==parseInt(tempm, 10)-1) && (tempDate.getDate()==parseInt(tempd, 10)))
   {
    return true;
   }
   else
   {
    
    return false;
   }
}

/*
获取指定页面元素的位置(x,y)
*/
function getElementPosition(elementId)
{     
    var ua = navigator.userAgent.toLowerCase();    
    var isOpera = (ua.indexOf('opera') != -1);    
    var isIE = (ua.indexOf('msie') != -1 && !isOpera); // not opera spoof     
    var el = document.getElementById(elementId);     
    if(el.parentNode === null || el.style.display == 'none')
    {        
        return false;    
    }     
    var parent = null;    
    var pos = [];    
    var box;     
    if(el.getBoundingClientRect)        
    {  
        //IE
        box = el.getBoundingClientRect();        
        var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);        
        var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);        
        return {x:box.left + scrollLeft, y:box.top + scrollTop};    
    }    
    else if(document.getBoxObjectFor)    // gecko    
    {        
        box = document.getBoxObjectFor(el);                    
        var borderLeft = (el.style.borderLeftWidth)?parseInt(el.style.borderLeftWidth):0;        
        var borderTop = (el.style.borderTopWidth)?parseInt(el.style.borderTopWidth):0;         
        pos = [box.x - borderLeft, box.y - borderTop];    
    }    
    else       
    {  
        //safari & opera
        pos = [el.offsetLeft, el.offsetTop];        
        parent = el.offsetParent;       
        if (parent != el)
        {            
           while (parent)
           {               
            pos[0] += parent.offsetLeft;               
            pos[1] += parent.offsetTop;                
            parent = parent.offsetParent;            
           }        
        }       
        if (ua.indexOf('opera') != -1  || ( ua.indexOf('safari') != -1 && el.style.position == 'absolute' ))         
        {
               pos[0] -= document.body.offsetLeft;                
               pos[1] -= document.body.offsetTop;        
        }     
    }            
    if (el.parentNode)
    {
        parent = el.parentNode;
    }
    else
    {
        parent = null;
    }       
    while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML')     
    {  
        //account for any scrolled ancestors       
        pos[0] -= parent.scrollLeft;       
        pos[1] -= parent.scrollTop;          
        if (parent.parentNode)
        {
            parent = parent.parentNode;
        }         
        else
        {
            parent = null;
        }    
    }    
 return {x:pos[0], y:pos[1]};
}


/*
得到QueryString值
------调用方法-------
var Request=new QueryString();
sID=Request["strID"];
*/
function QueryString()
{
    var name,value,i;
    var str=location.href;
    var num=str.indexOf("?")
    str=str.substr(num+1);
    var arrtmp=str.split("&");
    for(i=0;i < arrtmp.length;i++)
    {
        num=arrtmp[i].indexOf("=");
        if(num>0)
        {
            name=arrtmp[i].substring(0,num);
            value=arrtmp[i].substr(num+1);
            this[name]=value;
        }
    }
}

/*
判断是否为空
*/
function checkIsEmpty(val)
{
    if(trim(String(val))=="")
        return true;
    else
        return false;
}

/*
sDate1和sDate2是2002-12-18格式
*/
function DateDiff(sDate1, sDate2)
{
    var aDate, oDate1, oDate2, iDays;
    aDate = sDate1.split("-")
    oDate1 = new Date(aDate[1] + '/' + aDate[2] + '/' + aDate[0]) //转换为12-18-2002格式
    aDate = sDate2.split("-")
    oDate2 = new Date(aDate[1] + '/' + aDate[2] + '/' + aDate[0])
    iDays = parseInt((oDate1 - oDate2) / 1000 / 60 / 60 /24) //把相差的毫秒数转换为天数
    return iDays
}
/*
调用日历函数
*/
function showJrCalendar(v,checkIn,checkOut){
    if(v=="CHK_IN"){
        showCalendar(checkIn,true,checkIn,checkOut,checkOut,'','','','','','','');
    }else{
        showCalendar(checkOut,true,checkOut,null,null,'','','','','','','')
    }
}

/*
设置居中
*/
function setLayoutCenter(layerName){
    document.getElementById(layerName).style.left=(document.body.clientWidth-240)/2;
    var x = (document.getElementById(layerName).style.left).replace("px","");//浮动层固定于浏览器的x方向位置(从左往右)
    var y = 150;//浮动层固定于浏览器的y方向位置(从上往下)
    var diff = (parent.frames['mainFrame'].document.body.scrollTop + y - document.getElementById(layerName).style.posTop)*.20;
    var y = parent.frames['mainFrame'].document.body.scrollTop + y - diff;
    eval("document.all." + layerName + ".style.posTop = y");
    eval("document.all." + layerName + ".style.posLeft = x");//移动层
}

/*
滚动条顶部高度
*/
function getScrollTopHeight() {   
    var scrollTopHeight = 0;    
    if (typeof window.pageYOffset != 'undefined') {    
        scrollTopHeight = window.pageYOffset;    
    }    
    else if (typeof window.document.compatMode != 'undefined' &&    
       window.document.compatMode != 'BackCompat') {    
       scrollTopHeight = window.document.documentElement.scrollTop;    
    }    
    else if (typeof window.document.body != 'undefined') {    
       scrollTopHeight = window.document.body.scrollTop;    
    }    
    return scrollTopHeight;   
}
function getScrolls()
{    
  var sTop = 0, sLeft = 0, sWidth = 0, sHeight = 0;
       
  sTop = (document.body.scrollTop > document.documentElement.scrollTop)? document.body.scrollTop:document.documentElement.scrollTop;
  if( isNaN(sTop) || sTop <0 ){ sTop = 0 ;}
       
  sLeft = (document.body.scrollLeft > document.documentElement.scrollLeft )? document.body.scrollLeft:document.documentElement.scrollLeft;
  if( isNaN(sLeft) || sLeft <0 ){ sLeft = 0 ;}
  
  return { sTop:sTop, sLeft: sLeft, sWidth: sWidth, sHeight: sHeight };
}
/*层居中*/
function setCenter(name){
   var sc=getScrolls();
   var h1 = document.body.clientHeight;
   var h2 = document.documentElement.clientHeight;
   var isXhtml = (h2<=h1&&h2!=0)?true:false; //判断当前页面的Doctype是否为Xhtml
   var myBody = isXhtml?document.documentElement:document.body;
   var yy=myBody.clientHeight;
   var xx=myBody.clientWidth;
   var myobj=document.getElementById(name);
   var objhh=myobj.offsetHeight;
   var objww=myobj.offsetWidth;
   if(self!=top){
       if(objhh>yy)
         yy+=Math.abs(objhh-yy)+10;
   }
   myobj.style.position = "absolute";
   myobj.style.top=(yy-objhh)/2 + sc.sTop + "px";
   myobj.style.left=(xx-objww)/2 + "px";
}  
       
/*
鼠标拖动层(可任意绑定DIV标签)
联系方式:1034555083/zhanghuiguoanlige@126.com
调用方法:var myDrag=new Endrag(source,target,offSetX, offSetY);
参数说明:source--鼠标动作绑定对象;target--操作目标对象(要移动的对象);offSetX--横坐标偏移;offSetY--纵坐标偏移
说明:通过多次调用本方法绑定多个对象的拖动
*/
funs={
    index:1001, 
    getFocus:function (target){ 
        if(target.style.zIndex!=this.index){ 
            this.index += 2; 
            var idx = this.index; 
            target.style.zIndex=idx; 
        } 
    },
    abs:function (element) {
        var result = { x: element.offsetLeft, y: element.offsetTop};
        element = element.offsetParent;
        while (element) {
            result.x += element.offsetLeft;
            result.y += element.offsetTop;
            element = element.offsetParent;
        }
        return result;
    }
};
function dragDialog(source,target,offSetX, offSetY){
    source=typeof(source)=="object" ? source:document.getElementById(source);
    target=typeof(target)=="object" ? target:document.getElementById(target);
    var x0=0,y0=0,x1=0,y1=0,moveable=false,index=100,NS=(navigator.appName=='Netscape');
    offSetX=typeof offSetX== "undefined" ? 0:offSetX;
    offSetY=typeof offSetY== "undefined" ? 0:offSetY;
    source.οnmοusedοwn=function(e){
        e = e ? e : (window.event ? window.event : null);
        funs.getFocus(target);
        if(e.button==(NS)?0 :1)  {
            if(!NS){this.setCapture()}
            x0 = e.clientX ; 
            y0 = e.clientY ; 
            x1 = parseInt(funs.abs(target).x); 
            y1 = parseInt(funs.abs(target).y);   
            moveable = true; 
        } 
    }; 
    //拖动; 
    source.οnmοusemοve=function(e){
        e = e ? e : (window.event ? window.event : null); 
        if(moveable){ 
            target.style.left = (x1 + e.clientX - x0 - offSetX) + "px"; 
            target.style.top  = (y1 + e.clientY - y0 - offSetY) + "px"; 
        } 
    };
    //停止拖动; 
    source.οnmοuseup=function (e){
        if(moveable)  { 
            if(!NS){this.releaseCapture();}
            moveable = false; 
        } 
    };
}

mask= function(){
    var mybg;
    return {
        show:function(){
            if(!mybg){
                mybg = document.createElement("div");
                mybg.setAttribute("id","maskBodyBg");
                mybg.style.background = "#000";
                mybg.style.width = "100%";
                mybg.style.height = document.body.clientHeight + "px";
                mybg.style.position = "absolute";
                mybg.style.top = "0";
                mybg.style.left = "0";
                mybg.style.zIndex = "1000";
                mybg.style.opacity = "0.3";
                mybg.style.filter = "Alpha(opacity=30)";
                document.body.style.overflow = "auto";
                document.body.appendChild(mybg);
            }
            mybg.style.display="block";
//            var arrSel=document.getElementsByTagName("select");
//            for(var i=0;i<arrSel.length;i++){
//                arrSel[i].style.display='none';
//            }
         
        },
        hide:function(){
//            var arrSel=document.getElementsByTagName("select");
//            for(var i=0;i<arrSel.length;i++){
//                arrSel[i].style.display='';
//            }
          
            var oBg=document.getElementById("maskBodyBg");
            if(oBg)
            {
                oBg.style.display="none";
                }
             
          
        }
    }
}();

/*显示居中对话框*/
function showCenterDialog(id)
{
    var oDialog=document.getElementById(id);
    if(oDialog)
    {
        oDialog.style.display="block";
        setCenter(id);
    }
}
/*关闭对话框*/
function closeCommonDialog(id)
{
    var o=document.getElementById(id);
    if(o)
        o.style.display="none";
}

//验证正整数
var isInteger=function(num){
    var r= /^[1-9][0-9]*$/;  //正整数
    return r.test(num);
}

//验证整数
var isNumber=function(num){
    var r= /^/d+$/;  //整数
    return r.test(num);
}

var isDigital=function(num){
    var r= /^/d+(/.[0-9]{0,2})?%?$/;  //整数
    return r.test(num);
}


function clearDecimalSuffix(strValue,n){
    if(strValue.indexOf(".")>-1)
    {
        var cmm1=strValue.split(".")[0];
        var cmm2=strValue.split(".")[1];
        if(cmm2.length>=n)
        {
            cmm2=cmm2.substring(0,n);
        }
        else
        {
            for(var k=1;k<=n-cmm2.length;k++){
                cmm2+='0';
            }
        }
        strValue=cmm1 + "." + cmm2;
    }
    else
    {
        for(var p=1;p<=n;p++){
                if(p==1)
                    strValue=strValue + ".0";
                else
                    strValue=strValue + "0";
        }
    }
    return strValue;
}

/*初始化加载*/
function loadingInfo(msg){
    return "<table style='width:100%;border-collapse:collapse;' cellpadding='0' border='1' bordercolor='#999999' cellspacing='0'><tr><td style='text-align:center;color:Green;font-weight:bold; height:64px;line-height:64px;font-size:12px;'>" + msg + "</td></tr></table>";
}

 类似资料:

相关阅读

相关文章

相关问答