常用的javascript代碼

本文介绍了一个通用JavaScript库Common.js的功能及使用方法,包括字符串处理、XML编码、输入验证等实用函数,适用于网页开发中多种常见需求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

   1None.gif
   2ExpandedBlockStart.gifContractedBlock.gif/**//*
   3InBlock.gif
   4InBlock.gif       名字:Common.js
   5InBlock.gif
   6InBlock.gif       功能:通用JavaScript基本函數類庫
   7InBlock.gif
   8InBlock.gif       包括:
   9InBlock.gif
  10InBlock.gif                     1.Trim(str)--去除字符串兩邊的空格
  11InBlock.gif
  12InBlock.gif                     2.XMLEncode(str)--對字符串進行XML格式化
  13InBlock.gif
  14InBlock.gif            3.ShowLabel(str,str)--鼠標提示功能(顯示字符,提示字符)
  15InBlock.gif
  16InBlock.gif                     4.IsEmpty(obj)--判斷輸入框是否為空
  17InBlock.gif
  18InBlock.gif                     5.IsInt(objStr,sign,zero)--驗證是否為整數
  19InBlock.gif
  20InBlock.gif                     6.IsFloat(objStr,sign,zero)--驗證是否為浮點數
  21InBlock.gif
  22InBlock.gif                     7.IsEnLetter(objStr,size)--驗證是否為26個字母
  23InBlock.gif
  24ExpandedBlockEnd.gif*/

  25None.gif
  26None.gif==================================================================
  27None.gif
  28None.gif字符串操作
  29None.gif
  30None.gifTrim(string):去除字符串兩邊的空格
  31None.gif
  32None.gif==================================================================
  33None.gif
  34None.gif*/
  35None.gif
  36None.gif 
  37None.gif
  38ExpandedBlockStart.gifContractedBlock.gif/**//*
  39InBlock.gif
  40InBlock.gif==================================================================
  41InBlock.gif
  42InBlock.gifLTrim(string):去除左?的空格
  43InBlock.gif
  44InBlock.gif==================================================================
  45InBlock.gif
  46ExpandedBlockEnd.gif*/

  47None.gif
  48None.giffunction LTrim(str)
  49None.gif
  50ExpandedBlockStart.gifContractedBlock.gifdot.gif{
  51InBlock.gif
  52InBlock.gif    var whitespace = new String(" \t\n\r");
  53InBlock.gif
  54InBlock.gif    var s = new String(str);
  55InBlock.gif
  56InBlock.gif    
  57InBlock.gif
  58InBlock.gif    if (whitespace.indexOf(s.charAt(0)) != -1)
  59InBlock.gif
  60ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
  61InBlock.gif
  62InBlock.gif        var j=0, i = s.length;
  63InBlock.gif
  64InBlock.gif        while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
  65InBlock.gif
  66ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
  67InBlock.gif
  68InBlock.gif            j++;
  69InBlock.gif
  70ExpandedSubBlockEnd.gif        }

  71InBlock.gif
  72InBlock.gif        s = s.substring(j, i);
  73InBlock.gif
  74ExpandedSubBlockEnd.gif    }

  75InBlock.gif
  76InBlock.gif    return s;
  77InBlock.gif
  78ExpandedBlockEnd.gif}

  79None.gif
  80None.gif 
  81None.gif
  82ExpandedBlockStart.gifContractedBlock.gif/**//*
  83InBlock.gif
  84InBlock.gif==================================================================
  85InBlock.gif
  86InBlock.gifRTrim(string):去除右邊的空格
  87InBlock.gif
  88InBlock.gif==================================================================
  89InBlock.gif
  90ExpandedBlockEnd.gif*/

  91None.gif
  92None.giffunction RTrim(str)
  93None.gif
  94ExpandedBlockStart.gifContractedBlock.gifdot.gif{
  95InBlock.gif
  96InBlock.gif    var whitespace = new String(" \t\n\r");
  97InBlock.gif
  98InBlock.gif    var s = new String(str);
  99InBlock.gif
 100InBlock.gif 
 101InBlock.gif
 102InBlock.gif    if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
 103InBlock.gif
 104ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 105InBlock.gif
 106InBlock.gif        var i = s.length - 1;
 107InBlock.gif
 108InBlock.gif        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
 109InBlock.gif
 110ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 111InBlock.gif
 112InBlock.gif            i--;
 113InBlock.gif
 114ExpandedSubBlockEnd.gif        }

 115InBlock.gif
 116InBlock.gif        s = s.substring(0, i+1);
 117InBlock.gif
 118ExpandedSubBlockEnd.gif    }

 119InBlock.gif
 120InBlock.gif    return s;
 121InBlock.gif
 122ExpandedBlockEnd.gif}

 123None.gif
 124None.gif 
 125None.gif
 126ExpandedBlockStart.gifContractedBlock.gif/**//*
 127InBlock.gif
 128InBlock.gif==================================================================
 129InBlock.gif
 130InBlock.gifTrim(string):去除前后空格
 131InBlock.gif
 132InBlock.gif==================================================================
 133ExpandedBlockEnd.gif*/

 134None.gif
 135None.giffunction Trim(str)
 136None.gif
 137ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 138InBlock.gif
 139InBlock.gif    return RTrim(LTrim(str));
 140InBlock.gif
 141ExpandedBlockEnd.gif}

 142None.gif
 143ExpandedBlockStart.gifContractedBlock.gif/**//*
 144InBlock.gif
 145InBlock.gif================================================================================
 146InBlock.gif
 147InBlock.gifXMLEncode(string):對字符串進行XML編碼
 148InBlock.gif
 149InBlock.gif================================================================================
 150InBlock.gif
 151ExpandedBlockEnd.gif*/

 152None.gif
 153None.giffunction XMLEncode(str)
 154ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 155InBlock.gif
 156InBlock.gif       str=Trim(str);
 157InBlock.gif
 158InBlock.gif       str=str.replace("&","&amp;");
 159InBlock.gif
 160InBlock.gif       str=str.replace("<","&lt;");
 161InBlock.gif
 162InBlock.gif       str=str.replace(">","&gt;");
 163InBlock.gif
 164InBlock.gif       str=str.replace("'","&apos;");
 165InBlock.gif
 166InBlock.gif       str=str.replace("\"","&quot;");
 167InBlock.gif
 168InBlock.gif       return str;
 169InBlock.gif
 170ExpandedBlockEnd.gif}

 171None.gif
 172None.gif 
 173None.gif
 174ExpandedBlockStart.gifContractedBlock.gif/**//*
 175InBlock.gif
 176InBlock.gif================================================================================
 177InBlock.gif
 178InBlock.gif驗證類函數
 179InBlock.gif
 180InBlock.gif================================================================================
 181InBlock.gif
 182ExpandedBlockEnd.gif*/

 183None.giffunction IsEmpty(obj)
 184None.gif
 185ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 186InBlock.gif
 187InBlock.gif    obj=document.getElementsByName(obj).item(0);
 188InBlock.gif
 189InBlock.gif    if(Trim(obj.value)=="")
 190InBlock.gif
 191ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 192InBlock.gif
 193InBlock.gif        alert("字段不能為空。");        
 194InBlock.gif
 195InBlock.gif        if(obj.disabled==false && obj.readOnly==false)
 196InBlock.gif
 197ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 198InBlock.gif
 199InBlock.gif            obj.focus();
 200InBlock.gif
 201ExpandedSubBlockEnd.gif        }

 202InBlock.gif
 203ExpandedSubBlockEnd.gif    }

 204InBlock.gif
 205ExpandedBlockEnd.gif}

 206ExpandedBlockStart.gifContractedBlock.gif/**//*
 207InBlock.gif
 208InBlock.gifIsInt(string,string,int or string):(??字符串,+ or - or empty,empty or 0)
 209InBlock.gif
 210InBlock.gif功能:判定是否為整數,正整數,負整數,正整數+0,負整數+0
 211InBlock.gif
 212ExpandedBlockEnd.gif*/

 213None.gif
 214None.giffunction IsInt(objStr,sign,zero)
 215ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 216InBlock.gif
 217InBlock.gif    var reg;    
 218InBlock.gif
 219InBlock.gif    var bolzero;    
 220InBlock.gif
 221InBlock.gif    
 222InBlock.gif
 223InBlock.gif    if(Trim(objStr)=="")
 224InBlock.gif
 225ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 226InBlock.gif
 227InBlock.gif        return false;
 228InBlock.gif
 229ExpandedSubBlockEnd.gif    }

 230InBlock.gif
 231InBlock.gif    else
 232InBlock.gif
 233ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 234InBlock.gif
 235InBlock.gif        objStr=objStr.toString();
 236InBlock.gif
 237ExpandedSubBlockEnd.gif    }
    
 238InBlock.gif
 239InBlock.gif    
 240InBlock.gif
 241InBlock.gif    if((sign==null)||(Trim(sign)==""))
 242InBlock.gif
 243ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 244InBlock.gif
 245InBlock.gif        sign="+-";
 246InBlock.gif
 247ExpandedSubBlockEnd.gif    }

 248InBlock.gif
 249InBlock.gif    
 250InBlock.gif
 251InBlock.gif    if((zero==null)||(Trim(zero)==""))
 252InBlock.gif
 253ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 254InBlock.gif
 255InBlock.gif        bolzero=false;
 256InBlock.gif
 257ExpandedSubBlockEnd.gif    }

 258InBlock.gif
 259InBlock.gif    else
 260InBlock.gif
 261ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 262InBlock.gif
 263InBlock.gif        zero=zero.toString();
 264InBlock.gif
 265InBlock.gif        if(zero=="0")
 266InBlock.gif
 267ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 268InBlock.gif
 269InBlock.gif            bolzero=true;
 270InBlock.gif
 271ExpandedSubBlockEnd.gif        }

 272InBlock.gif
 273InBlock.gif        else
 274InBlock.gif
 275ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 276InBlock.gif
 277InBlock.gif            alert("檢查是否包含0參數,只可為(空、0)");
 278InBlock.gif
 279ExpandedSubBlockEnd.gif        }

 280InBlock.gif
 281ExpandedSubBlockEnd.gif    }

 282InBlock.gif
 283InBlock.gif    
 284InBlock.gif
 285InBlock.gif    switch(sign)
 286InBlock.gif
 287ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 288InBlock.gif
 289InBlock.gif        case "+-":
 290InBlock.gif
 291InBlock.gif            //整數
 292InBlock.gif
 293InBlock.gif            reg=/(^-?|^\+?)\d+$/;            
 294InBlock.gif
 295InBlock.gif            break;
 296InBlock.gif
 297InBlock.gif        case "+"
 298InBlock.gif
 299InBlock.gif            if(!bolzero)           
 300InBlock.gif
 301ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 302InBlock.gif
 303InBlock.gif                //正整數
 304InBlock.gif
 305InBlock.gif                reg=/^\+?[0-9]*[1-9][0-9]*$/;
 306InBlock.gif
 307ExpandedSubBlockEnd.gif            }

 308InBlock.gif
 309InBlock.gif            else
 310InBlock.gif
 311ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 312InBlock.gif
 313InBlock.gif                //正整數+0
 314InBlock.gif
 315InBlock.gif                //reg=/^\+?\d+$/;
 316InBlock.gif
 317InBlock.gif                reg=/^\+?[0-9]*[0-9][0-9]*$/;
 318InBlock.gif
 319ExpandedSubBlockEnd.gif            }

 320InBlock.gif
 321InBlock.gif            break;
 322InBlock.gif
 323InBlock.gif        case "-":
 324InBlock.gif
 325InBlock.gif            if(!bolzero)
 326InBlock.gif
 327ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 328InBlock.gif
 329InBlock.gif                //負整數
 330InBlock.gif
 331InBlock.gif                reg=/^-[0-9]*[1-9][0-9]*$/;
 332InBlock.gif
 333ExpandedSubBlockEnd.gif            }

 334InBlock.gif
 335InBlock.gif            else
 336InBlock.gif
 337ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 338InBlock.gif
 339InBlock.gif                //負整數+0
 340InBlock.gif
 341InBlock.gif                //reg=/^-\d+$/;
 342InBlock.gif
 343InBlock.gif                reg=/^-[0-9]*[0-9][0-9]*$/;
 344InBlock.gif
 345ExpandedSubBlockEnd.gif            }
            
 346InBlock.gif
 347InBlock.gif            break;
 348InBlock.gif
 349InBlock.gif        default:
 350InBlock.gif
 351InBlock.gif            alert("檢查符號參數,只可為(空、+、-)");
 352InBlock.gif
 353InBlock.gif            return false;
 354InBlock.gif
 355InBlock.gif            break;
 356InBlock.gif
 357ExpandedSubBlockEnd.gif    }

 358InBlock.gif
 359InBlock.gif    
 360InBlock.gif
 361InBlock.gif    var r=objStr.match(reg);
 362InBlock.gif
 363InBlock.gif    if(r==null)
 364InBlock.gif
 365ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 366InBlock.gif
 367InBlock.gif        return false;
 368InBlock.gif
 369ExpandedSubBlockEnd.gif    }

 370InBlock.gif
 371InBlock.gif    else
 372InBlock.gif
 373ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{        
 374InBlock.gif
 375InBlock.gif        return true;     
 376InBlock.gif
 377ExpandedSubBlockEnd.gif    }

 378InBlock.gif
 379ExpandedBlockEnd.gif}

 380None.gif
 381ExpandedBlockStart.gifContractedBlock.gif/**//*
 382InBlock.gif
 383InBlock.gifIsFloat(string,string,int or string):(檢查字符串,+ or - or empty,empty or 0)
 384InBlock.gif
 385InBlock.gif功能:判定是否為浮點數、正浮點數、負浮點數、正浮點數+0、負浮點數+0
 386InBlock.gif
 387ExpandedBlockEnd.gif*/

 388None.giffunction IsFloat(objStr,sign,zero)
 389None.gif
 390ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 391InBlock.gif
 392InBlock.gif    var reg;    
 393InBlock.gif
 394InBlock.gif    var bolzero;    
 395InBlock.gif
 396InBlock.gif    
 397InBlock.gif
 398InBlock.gif    if(Trim(objStr)=="")
 399InBlock.gif
 400ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 401InBlock.gif
 402InBlock.gif        return false;
 403InBlock.gif
 404ExpandedSubBlockEnd.gif    }

 405InBlock.gif
 406InBlock.gif    else
 407InBlock.gif
 408ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 409InBlock.gif
 410InBlock.gif        objStr=objStr.toString();
 411InBlock.gif
 412ExpandedSubBlockEnd.gif    }
    
 413InBlock.gif
 414InBlock.gif    
 415InBlock.gif
 416InBlock.gif    if((sign==null)||(Trim(sign)==""))
 417InBlock.gif
 418ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 419InBlock.gif
 420InBlock.gif        sign="+-";
 421InBlock.gif
 422ExpandedSubBlockEnd.gif    }

 423InBlock.gif
 424InBlock.gif    
 425InBlock.gif
 426InBlock.gif    if((zero==null)||(Trim(zero)==""))
 427InBlock.gif
 428ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 429InBlock.gif
 430InBlock.gif        bolzero=false;
 431InBlock.gif
 432ExpandedSubBlockEnd.gif    }

 433InBlock.gif
 434InBlock.gif    else
 435InBlock.gif
 436ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 437InBlock.gif
 438InBlock.gif        zero=zero.toString();
 439InBlock.gif
 440InBlock.gif        if(zero=="0")
 441InBlock.gif
 442ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 443InBlock.gif
 444InBlock.gif            bolzero=true;
 445InBlock.gif
 446ExpandedSubBlockEnd.gif        }

 447InBlock.gif
 448InBlock.gif        else
 449InBlock.gif
 450ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 451InBlock.gif
 452InBlock.gif            alert("?查是否包含0參數,只可為(空、0)");
 453InBlock.gif
 454ExpandedSubBlockEnd.gif        }

 455InBlock.gif
 456ExpandedSubBlockEnd.gif    }

 457InBlock.gif
 458InBlock.gif    
 459InBlock.gif
 460InBlock.gif    switch(sign)
 461InBlock.gif
 462ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 463InBlock.gif
 464InBlock.gif        case "+-":
 465InBlock.gif
 466InBlock.gif            //浮點數
 467InBlock.gif
 468InBlock.gif            reg=/^((-?|\+?)\d+)(\.\d+)?$/;
 469InBlock.gif
 470InBlock.gif            break;
 471InBlock.gif
 472InBlock.gif        case "+"
 473InBlock.gif
 474InBlock.gif            if(!bolzero)           
 475InBlock.gif
 476ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 477InBlock.gif
 478InBlock.gif                //正浮點數
 479InBlock.gif
 480InBlock.gif                reg=/^\+?(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/;
 481InBlock.gif
 482ExpandedSubBlockEnd.gif            }

 483InBlock.gif
 484InBlock.gif            else
 485InBlock.gif
 486ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 487InBlock.gif
 488InBlock.gif                //正浮點數+0
 489InBlock.gif
 490InBlock.gif                reg=/^\+?\d+(\.\d+)?$/;
 491InBlock.gif
 492ExpandedSubBlockEnd.gif            }

 493InBlock.gif
 494InBlock.gif            break;
 495InBlock.gif
 496InBlock.gif        case "-":
 497InBlock.gif
 498InBlock.gif            if(!bolzero)
 499InBlock.gif
 500ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 501InBlock.gif
 502InBlock.gif                //負浮點數
 503InBlock.gif
 504InBlock.gif                reg=/^-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/;
 505InBlock.gif
 506ExpandedSubBlockEnd.gif            }

 507InBlock.gif
 508InBlock.gif            else
 509InBlock.gif
 510ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 511InBlock.gif
 512InBlock.gif                //負浮點數+0
 513InBlock.gif
 514InBlock.gif                reg=/^((-\d+(\.\d+)?)|(0+(\.0+)?))$/;
 515InBlock.gif
 516ExpandedSubBlockEnd.gif            }
            
 517InBlock.gif
 518InBlock.gif            break;
 519InBlock.gif
 520InBlock.gif        default:
 521InBlock.gif
 522InBlock.gif            alert("檢查符號參數,只可為(空、+、-)");
 523InBlock.gif
 524InBlock.gif            return false;
 525InBlock.gif
 526InBlock.gif            break;
 527InBlock.gif
 528ExpandedSubBlockEnd.gif    }

 529InBlock.gif
 530InBlock.gif    
 531InBlock.gif
 532InBlock.gif    var r=objStr.match(reg);
 533InBlock.gif
 534InBlock.gif    if(r==null)
 535InBlock.gif
 536ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 537InBlock.gif        return false;
 538ExpandedSubBlockEnd.gif    }

 539InBlock.gif    else
 540InBlock.gif
 541ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{        
 542InBlock.gif        return true;     
 543ExpandedSubBlockEnd.gif    }

 544ExpandedBlockEnd.gif}

 545ExpandedBlockStart.gifContractedBlock.gif/**//*
 546InBlock.gif
 547InBlock.gifIsEnLetter(string,string):驗證字符串,大小寫(UL,U,L or ul,u,l)
 548InBlock.gif
 549ExpandedBlockEnd.gif*/

 550None.gif
 551None.giffunction IsEnLetter(objStr,size)
 552None.gif
 553ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 554InBlock.gif
 555InBlock.gif    var reg;
 556InBlock.gif
 557InBlock.gif    
 558InBlock.gif
 559InBlock.gif    if(Trim(objStr)=="")
 560InBlock.gif
 561ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 562InBlock.gif
 563InBlock.gif        return false;
 564InBlock.gif
 565ExpandedSubBlockEnd.gif    }

 566InBlock.gif
 567InBlock.gif    else
 568InBlock.gif
 569ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 570InBlock.gif
 571InBlock.gif        objStr=objStr.toString();
 572InBlock.gif
 573ExpandedSubBlockEnd.gif    }
    
 574InBlock.gif
 575InBlock.gif    
 576InBlock.gif
 577InBlock.gif    if((size==null)||(Trim(size)==""))
 578InBlock.gif
 579ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 580InBlock.gif
 581InBlock.gif        size="UL";
 582InBlock.gif
 583ExpandedSubBlockEnd.gif    }

 584InBlock.gif
 585InBlock.gif    else
 586InBlock.gif
 587ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 588InBlock.gif
 589InBlock.gif        size=size.toUpperCase();
 590InBlock.gif
 591ExpandedSubBlockEnd.gif    }

 592InBlock.gif
 593InBlock.gif    
 594InBlock.gif
 595InBlock.gif    switch(size)
 596InBlock.gif
 597ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 598InBlock.gif
 599InBlock.gif        case "UL":
 600InBlock.gif
 601InBlock.gif            //大小寫
 602InBlock.gif
 603InBlock.gif            reg=/^[A-Za-z]+$/;
 604InBlock.gif
 605InBlock.gif            break;
 606InBlock.gif
 607InBlock.gif        case "U"
 608InBlock.gif
 609InBlock.gif            //大寫
 610InBlock.gif
 611InBlock.gif            reg=/^[A-Z]+$/;
 612InBlock.gif
 613InBlock.gif            break;
 614InBlock.gif
 615InBlock.gif        case "L":
 616InBlock.gif
 617InBlock.gif            //小寫
 618InBlock.gif            reg=/^[a-z]+$/;
 619InBlock.gif
 620InBlock.gif            break;
 621InBlock.gif
 622InBlock.gif        default:
 623InBlock.gif
 624InBlock.gif            alert("?查大小寫參數,只可為(空、UL、U、L)");
 625InBlock.gif
 626InBlock.gif            return false;
 627InBlock.gif
 628InBlock.gif            break;
 629InBlock.gif
 630ExpandedSubBlockEnd.gif    }

 631InBlock.gif
 632InBlock.gif    
 633InBlock.gif
 634InBlock.gif    var r=objStr.match(reg);
 635InBlock.gif
 636InBlock.gif    if(r==null)
 637InBlock.gif
 638ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 639InBlock.gif
 640InBlock.gif        return false;
 641InBlock.gif
 642ExpandedSubBlockEnd.gif    }

 643InBlock.gif
 644InBlock.gif    else
 645InBlock.gif
 646ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{        
 647InBlock.gif
 648InBlock.gif        return true;     
 649InBlock.gif
 650ExpandedSubBlockEnd.gif    }

 651InBlock.gif
 652ExpandedBlockEnd.gif}

 653None.gif
 654None.gif 
 655None.gif
 656None.gif 
 657None.gif
 658ExpandedBlockStart.gifContractedBlock.gif/**//*
 659InBlock.gif
 660InBlock.gif================================================================================
 661InBlock.gif
 662InBlock.gif功能:鼠標小提示
 663InBlock.gif
 664InBlock.gif
 665InBlock.gif================================================================================
 666InBlock.gif
 667ExpandedBlockEnd.gif*/

 668None.gif
 669None.gif 
 670None.gif
 671None.gif//定異變量、設置默認值
 672None.gif
 673None.gifvar LabelFontFace="宋体,arial,Verdana";
 674None.gif
 675None.gifvar LabelFontColor="#000000";
 676None.gif
 677None.gifvar LabelFontSize="9pt";
 678None.gif
 679None.gifvar LabelFontStyle="Font.PLAIN";
 680None.gif
 681None.gifvar LabelBorderColor="#000000";
 682None.gif
 683None.gifvar LabelBackColor="#FFFFE1";
 684None.gif
 685None.gif 
 686None.gif
 687None.gif//設置各個屬性
 688None.gif
 689None.giffunction SetLabelFontFace(obj)
 690None.gif
 691ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 692InBlock.gif
 693InBlock.gif       obj=Trim(obj);
 694InBlock.gif
 695InBlock.gif       if(obj==null || obj=="")
 696InBlock.gif
 697ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif{
 698InBlock.gif
 699InBlock.gif              obj="宋体,arial,Verdana";
 700InBlock.gif
 701ExpandedSubBlockEnd.gif       }

 702InBlock.gif
 703InBlock.gif       LabelFontFace=obj;
 704InBlock.gif
 705ExpandedBlockEnd.gif}

 706None.gif
 707None.gif 
 708None.gif
 709None.giffunction SetLabelFontColor(obj)
 710None.gif
 711ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 712InBlock.gif
 713InBlock.gif    obj=Trim(obj);
 714InBlock.gif
 715InBlock.gif       if(obj==null || obj=="")
 716InBlock.gif
 717ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif{
 718InBlock.gif
 719InBlock.gif              obj="#000000";
 720InBlock.gif
 721ExpandedSubBlockEnd.gif       }

 722InBlock.gif
 723InBlock.gif       LabelFontColor=obj;
 724InBlock.gif
 725ExpandedBlockEnd.gif}

 726None.gif
 727None.gif 
 728None.gif
 729None.giffunction SetLabelFontSize(obj)
 730None.gif
 731ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 732InBlock.gif
 733InBlock.gif    obj=Trim(obj);
 734InBlock.gif
 735InBlock.gif       if(obj==null || obj=="")
 736InBlock.gif
 737ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif{
 738InBlock.gif
 739InBlock.gif              obj="9pt";
 740InBlock.gif
 741ExpandedSubBlockEnd.gif       }

 742InBlock.gif
 743InBlock.gif       LabelFontSize=obj;
 744InBlock.gif
 745ExpandedBlockEnd.gif}

 746None.gif
 747None.gif 
 748None.gif
 749None.giffunction SetLabelFontStyle(obj)
 750None.gif
 751ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 752InBlock.gif
 753InBlock.gif    obj=Trim(obj);
 754InBlock.gif
 755InBlock.gif       if(obj==null || obj=="")
 756InBlock.gif
 757ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif{
 758InBlock.gif
 759InBlock.gif              obj="Font.PLAIN";
 760InBlock.gif
 761ExpandedSubBlockEnd.gif       }

 762InBlock.gif
 763InBlock.gif       LabelFontStyle=obj;
 764InBlock.gif
 765ExpandedBlockEnd.gif}

 766None.gif
 767None.gif 
 768None.gif
 769None.giffunction SetLabelBorderColor(obj)
 770None.gif
 771ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 772InBlock.gif
 773InBlock.gif    obj=Trim(obj);
 774InBlock.gif
 775InBlock.gif    if(obj==null || obj=="")
 776InBlock.gif
 777ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 778InBlock.gif
 779InBlock.gif        obj="#000000";
 780InBlock.gif
 781ExpandedSubBlockEnd.gif    }

 782InBlock.gif
 783InBlock.gif    LabelBorderColor=obj;
 784InBlock.gif
 785ExpandedBlockEnd.gif}

 786None.giffunction SetLabelBackColor(obj)
 787None.gif
 788ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 789InBlock.gif
 790InBlock.gif    obj=Trim(obj);
 791InBlock.gif
 792InBlock.gif    if(obj==null || obj=="")
 793InBlock.gif
 794ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 795InBlock.gif
 796InBlock.gif        obj="#FFFFE1";
 797InBlock.gif
 798ExpandedSubBlockEnd.gif    }

 799InBlock.gif
 800InBlock.gif    LabelBackColor=obj;
 801InBlock.gif
 802ExpandedBlockEnd.gif}

 803None.gif
 804None.gif//合成文字樣式
 805None.gif
 806None.giffunction SetTextStyle(str)
 807None.gif
 808ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 809InBlock.gif
 810InBlock.gif    var strRet="";
 811InBlock.gif
 812InBlock.gif    
 813InBlock.gif
 814InBlock.gif    var strStyle="";
 815InBlock.gif
 816InBlock.gif    
 817InBlock.gif
 818InBlock.gif    strStyle="font-family:"+LabelFontFace+";";
 819InBlock.gif
 820InBlock.gif    strStyle+="color:"+LabelFontColor+";";
 821InBlock.gif
 822InBlock.gif    strStyle+="font-size:"+LabelFontSize+";";
 823InBlock.gif
 824InBlock.gif    switch(LabelFontStyle.toLowerCase())
 825InBlock.gif
 826ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 827InBlock.gif
 828InBlock.gif        case "font.plain":
 829InBlock.gif
 830InBlock.gif            strStyle+="font-weight: normal;";
 831InBlock.gif
 832InBlock.gif            strStyle+="font-style: normal;";
 833InBlock.gif
 834InBlock.gif            break;
 835InBlock.gif
 836InBlock.gif        case "font.bold":
 837InBlock.gif
 838InBlock.gif            strStyle+="font-weight: bold;";
 839InBlock.gif
 840InBlock.gif            strStyle+="font-style: normal;";
 841InBlock.gif
 842InBlock.gif            break;
 843InBlock.gif
 844InBlock.gif        case "font.italic":
 845InBlock.gif
 846InBlock.gif            strStyle+="font-weight: normal;";
 847InBlock.gif
 848InBlock.gif            strStyle+="font-style: italic;";
 849InBlock.gif
 850InBlock.gif            break;
 851InBlock.gif
 852InBlock.gif        case "font.italicbold":
 853InBlock.gif
 854InBlock.gif        case "font.bolditalic":
 855InBlock.gif
 856InBlock.gif            strStyle+="font-weight: bold;";
 857InBlock.gif
 858InBlock.gif            strStyle+="font-style: italic;";
 859InBlock.gif
 860InBlock.gif            break;
 861InBlock.gif
 862InBlock.gif        default:
 863InBlock.gif
 864InBlock.gif            strStyle+="font-weight: bold;";
 865InBlock.gif
 866InBlock.gif            strStyle+="font-style: italic;";
 867InBlock.gif
 868InBlock.gif            break;
 869InBlock.gif
 870ExpandedSubBlockEnd.gif    }

 871InBlock.gif
 872InBlock.gif    
 873InBlock.gif
 874InBlock.gif    strRet="<font style='"+strStyle+"'>";
 875InBlock.gif
 876InBlock.gif    strRet+="&nbsp;"+str+"&nbsp;";
 877InBlock.gif
 878InBlock.gif    strRet+="</font>";
 879InBlock.gif
 880InBlock.gif    
 881InBlock.gif
 882InBlock.gif    return strRet;
 883InBlock.gif
 884ExpandedBlockEnd.gif}

 885None.gif
 886None.gif 
 887None.gif
 888None.gif//合成表格樣式
 889None.gif
 890None.giffunction SetTableStyle()
 891None.gif
 892ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 893InBlock.gif
 894InBlock.gif    var strRet="";
 895InBlock.gif
 896InBlock.gif    
 897InBlock.gif
 898InBlock.gif    strRet+="border-right: "+LabelBorderColor+" 1px solid;";
 899InBlock.gif
 900InBlock.gif    strRet+="border-top: "+LabelBorderColor+" 1px solid;";
 901InBlock.gif
 902InBlock.gif    strRet+="border-left: "+LabelBorderColor+" 1px solid;";
 903InBlock.gif
 904InBlock.gif    strRet+="border-bottom: "+LabelBorderColor+" 1px solid;";
 905InBlock.gif
 906InBlock.gif    strRet+="background-color:"+LabelBackColor;    
 907InBlock.gif
 908InBlock.gif    
 909InBlock.gif
 910InBlock.gif    return strRet;
 911InBlock.gif
 912ExpandedBlockEnd.gif}

 913None.gif
 914None.gif 
 915None.gif
 916None.gif//顯示提示
 917None.gif
 918None.giffunction ShowNote(str)
 919None.gif
 920ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 921InBlock.gif
 922InBlock.gif       var strHtml;
 923InBlock.gif
 924InBlock.gif       
 925InBlock.gif
 926InBlock.gif       strHtml="";
 927InBlock.gif
 928InBlock.gif       strHtml+="<table height=1px width=1px border='0'cellspacing='0' cellpadding='0' style='" + SetTableStyle() + "'>";
 929InBlock.gif
 930InBlock.gif       strHtml+="<tr>";
 931InBlock.gif
 932InBlock.gif       strHtml+="<td>"+SetTextStyle(str)+"</td>";
 933InBlock.gif
 934InBlock.gif       strHtml+="</tr>";
 935InBlock.gif
 936InBlock.gif       strHtml+="</table>";                           
 937InBlock.gif
 938InBlock.gif       
 939InBlock.gif
 940InBlock.gif       if (document.all&&document.readyState=="complete")
 941InBlock.gif
 942ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif{                                        
 943InBlock.gif
 944InBlock.gif              document.all.div_Note.innerHTML=strHtml;
 945InBlock.gif
 946InBlock.gif              document.all.div_Note.style.pixelLeft=event.clientX+document.body.scrollLeft+10
 947InBlock.gif
 948InBlock.gif              document.all.div_Note.style.pixelTop=event.clientY+document.body.scrollTop+10
 949InBlock.gif
 950InBlock.gif              document.all.div_Note.style.visibility="visible"
 951InBlock.gif
 952ExpandedSubBlockEnd.gif       }
     
 953InBlock.gif
 954ExpandedBlockEnd.gif}

 955None.gif
 956None.gif 
 957None.gif
 958None.gif//隱藏提示
 959None.gif
 960None.giffunction HideNote()
 961None.gif
 962ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 963InBlock.gif
 964InBlock.gif       if (document.all)
 965InBlock.gif
 966ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif{
 967InBlock.gif
 968InBlock.gif              document.all.div_Note.style.visibility="hidden";
 969InBlock.gif
 970ExpandedSubBlockEnd.gif       }

 971InBlock.gif
 972InBlock.gif       else
 973InBlock.gif
 974ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif{
 975InBlock.gif
 976InBlock.gif              if (document.layers)
 977InBlock.gif
 978ExpandedSubBlockStart.gifContractedSubBlock.gif              dot.gif{
 979InBlock.gif
 980InBlock.gif                     clearInterval(currentscroll)
 981InBlock.gif
 982InBlock.gif                     document.div_Note.visibility="hidden";
 983InBlock.gif
 984ExpandedSubBlockEnd.gif              }

 985InBlock.gif
 986ExpandedSubBlockEnd.gif       }
                                 
 987InBlock.gif
 988ExpandedBlockEnd.gif}

 989None.gif
 990None.gif 
 991None.gif
 992None.gif//初始化
 993None.gif
 994None.giffunction Init()
 995None.gif
 996ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 997InBlock.gif
 998InBlock.gif    window.document.write("<div id=\"div_Note\" style=\"VISIBILITY:hidden; POSITION:absolute; HEIGHT:13px;z-index:1\"></div>");
 999InBlock.gif
1000ExpandedBlockEnd.gif}

1001None.gif
1002None.gifInit();
1003None.gif
1004None.gif 
1005None.gif
1006None.gif//生成提示字符
1007None.gif
1008None.giffunction ShowLabel(text,note,bclick)
1009None.gif
1010ExpandedBlockStart.gifContractedBlock.gifdot.gif{
1011InBlock.gif
1012InBlock.gif       if(bclick!=null)
1013InBlock.gif
1014ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif{
1015InBlock.gif
1016InBlock.gif              return "<a href=\"#\" onMouseOver=\"ShowNote('" + note + "')\" onMouseOut=\"HideNote()\" onClick=\"JavaScript:DoSomeThing(this);\">" + text + "</a>";
1017InBlock.gif
1018ExpandedSubBlockEnd.gif       }

1019InBlock.gif
1020InBlock.gif       else
1021InBlock.gif
1022ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif{
1023InBlock.gif
1024InBlock.gif           return "<a href=\"#\" onMouseOver=\"ShowNote('" + note + "')\" onMouseOut=\"HideNote()\">" + text + "</a>";
1025InBlock.gif
1026ExpandedSubBlockEnd.gif       }

1027ExpandedBlockEnd.gif}

1028ExpandedBlockStart.gifContractedBlock.gif/**/////////////////////////////////////////////////////////////////////////////////////
1029None.gif//只能輸入中文 function onlychinese() 
1030ExpandedBlockStart.gifContractedBlock.gif/**////例子:onkeypress="onlychinese() "
1031ExpandedBlockEnd.gif/////////////////////////////////////////////////////////////////////////////////////

1032None.giffunction onlychinese() 
1033ExpandedBlockStart.gifContractedBlock.gifdot.gif{
1034InBlock.gifif ((window.event.keyCode >=32&& (window.event.keyCode <= 126)) 
1035ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
1036InBlock.gifwindow.event.keyCode = 0 ;
1037ExpandedSubBlockEnd.gif}

1038ExpandedBlockEnd.gif}
 
1039None.gif
1040ExpandedBlockStart.gifContractedBlock.gif/**////////////////////////////////////////////////////////////////////////////////
1041InBlock.gif///只能輸入數字 JHshNumberText()
1042InBlock.gif///onKeypress="JHshNumberText()"
1043ExpandedBlockEnd.gif//////////////////////////////////////////////////////////////////////////////

1044None.giffunction JHshNumberText()
1045ExpandedBlockStart.gifContractedBlock.gifdot.gif{
1046InBlock.gifif ( !(((window.event.keyCode >= 48&& (window.event.keyCode <= 57)) 
1047InBlock.gif|| (window.event.keyCode == 13|| (window.event.keyCode == 46
1048InBlock.gif|| (window.event.keyCode == 45)))
1049ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
1050InBlock.gifwindow.event.keyCode = 0 ;
1051ExpandedSubBlockEnd.gif}

1052ExpandedBlockEnd.gif}
 
1053None.gif
1054None.gif
1055None.gif

转载于:https://www.cnblogs.com/suifeng624/archive/2007/02/09/645701.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值