作家
登录

(推荐一个超好的JS函数库)S.Sams Lifexperience ScriptClassLib

作者: 来源:www.28hudong.com 2013-03-30 03:30:08 阅读 我要评论

1/**//*------------------------------------------------------------ 2 * S.Sams Lifexperience 3 * CopyRight (C) 2003-2007 S.Sams Lifexperience ScriptClassLib 4 * MSNLive: S.Sams#msn.com 5 * Http://blog.8see.net/ 6 * UPdate by : 2007-01-19 转载传播请保留版权 7 *-----------------------------------------------------------*/ 8 9 10/**//* $ 获取指定对象 11 @element 对象名 12 可以使用对象名集合,返回值为对象的集合 13 如果您使用了 Prototype 类库, 请把该函数注释掉 14 Sams_object.Get() 中同样实现该函数的所有功能 15*/ 16function $(element) { 17 if (arguments.length > 1) { 18 for (var i = 0, elements = [], length = arguments.length; i < length; i++) 19 elements.push($(arguments[i])); 20 return elements; 21 } 22 if (typeof element == 'string') 23 element = document.getElementById(element); 24 return element; 25} 26 27/// 浏览器相关操作 28var Sams_browse = { 29 /**//* 检测浏览信息 */ 30 checkBrowser : function () 31 { 32 this.ver=navigator.appVersion 33 this.dom=document.getElementById?1:0 34 this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0; 35 this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0; 36 this.ie4=(document.all && !this.dom)?1:0; 37 this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0; 38 this.ns4=(document.layers && !this.dom)?1:0; 39 this.mac=(this.ver.indexOf('Mac') > -1) ?1:0; 40 this.ope=(navigator.userAgent.indexOf('Opera')>-1); 41 this.ie=(this.ie6 || this.ie5 || this.ie4) 42 this.ns=(this.ns4 || this.ns5) 43 this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns5 || this.ns4 || this.mac || this.ope) 44 this.nbw=(!this.bw) 45 return this; 46 }, 47 48 /**//* 设为首页 49 @url 要设为首页的地址 50 */ 51 SetDefault : function () 52 { 53 this.style.behavior='url(#default#homepage)'; 54 this.setHomePage(this.GetUrl()); 55 return false; 56 }, 57 58 /**//* 复制指定URL地址 59 @Msg 要写入剪贴板的字符集 60 */ 61 SetCopy : function (Msg){ 62 if(navigator.userAgent.toLowerCase().indexOf('ie') > -1) { 63 clipboardData.setData('Text',Msg); 64 alert ("网址“"+Msg+"”n已经复制到您的剪贴板中n您可以使用Ctrl+V快捷键粘贴到需要的地方"); 65 } 66 else 67 { 68 prompt("请复制网站地址:",Msg); 69 } 70 }, 71 72 /**//* 加入收藏 73 @site 站点名称 74 @url 地址 75 */ 76 AddBookmark : function (site, url){ 77 if(navigator.userAgent.toLowerCase().indexOf('ie') > -1) { 78 window.external.addFavorite(url,site) 79 } else if (navigator.userAgent.toLowerCase().indexOf('opera') > -1) { 80 alert ("请使用Ctrl+T将本页加入收藏夹"); 81 } else { 82 alert ("请使用Ctrl+D将本页加入收藏夹"); 83 } 84 }, 85 86 /**//* 打开Url指定宽度和高度的窗口 */ 87 OpenWindows : function (url,width,height) 88 { 89 window.open(url,'newwin','width='+width+',height='+height); 90 return false; 91 }, 92 93 /**//* 禁止浏览器的Javascript错误提示 */ 94 CloseError : function(){ 95 window.onerror = function(){return true;}; 96 }, 97 98 /**//* 获取浏览器URL */ 99 GetUrl : function(){ 100 return location.href; 101 }, 102 103 /**//* 获取URL参数 */ 104 GetUrlParam : function(){ 105 return location.search; 106 }, 107 108 /**//* 获取页面来源 */ 109 GetFrom : function(){ 110 return document.referrer; 111 }, 112 113 /**//* 获取指定的URL参数值 114 @name 参数名 115 */ 116 Request : function(name){ 117 var GetUrl = this.GetUrl(); 118 var Plist = new Array(); 119 if(GetUrl.indexOf('?') > 0) 120 { 121 Plist = GetUrl.split('?')[1].split('&'); 122 } 123 else if(GetUrl.indexOf('#') > 0) 124 { 125 Plist = GetUrl.split('#')[1].split('&'); 126 } 127 if (GetUrl.length > 0) 128 { 129 for(var i=0; i<Plist.length; i++) 130 { 131 var GetValue = Plist[i].split('='); 132 if (GetValue[0].toUpperCase() == name.toUpperCase()) 133 { 134 return GetValue[1]; 135 break; 136 } 137 } 138 return; 139 } 140 }, 141 142 /**//* 直接将HTML写到新窗口 143 @title 标题 144 @msg 内容 145 */ 146 Popmsg : function PopIt(title,msg) 147 { 148 var popup = window.open('','popDialog','height=500,width=400,scrollbars=yes'); 149 popup.document.write('<html><title>'+title+'</title><style>body{margin:10px;font:13px Arial;}span{text-line:20px;}</style><body><span style='font:14px arial;'>'+msg + '</span></body></html>'); 150 popup.document.close(); 151 } 152}; 153 154 155/// 对象操作 156var Sams_object = { 157 158 /**//* 创建一个DIV对象 159 @ID 要创建的对象ID 160 @ClassName 创建对象的Class 161 @SetValue 设置该对象值 162 @ToDiv 将对象追加到指定的对象,如指定的对象不存在,则追加在Body的后面 163 返回 创建后的对象 164 */ 165 CreateDiv : function (ID,ClassName,SetValue,ToDiv){ 166 var creatediv = document.createElement('div'); 167 if(ID != null) creatediv.id = ID; 168 creatediv.style.position = 'absolute'; 169 if(ClassName != null) creatediv.className = ClassName; 170 if(this.Get(ToDiv)) 171 { 172 this.Get(ToDiv).appendChild(creatediv); 173 } 174 else 175 { 176 document.getElementsByTagName('body')[0].appendChild(creatediv); 177 } 178 this.SetValue(ID,SetValue); 179 return this.Get(ID); 180 }, 181 182 /**//* 删除指定DIV对象 183 @objid 要删除的对象ID 184 返回 Bool 操作结果 185 */ 186 DeleteDiv : function (objid) 187 { 188 try 189 { 190 if(this.Get(objid)) 191 { 192 var GetParent = this.Get(objid).parentNode; 193 GetParent.removeChild(this.Get(objid)); 194 return true; 195 } 196 else 197 { 198 return false; 199 } 200 } 201 catch(e) 202 { 203 return false; 204 } 205 }, 206 207 /**//* 获取浏览器对象 208 @id 要获取的对象ID 209 可以使用对象名集合,返回值为对象的集合 210 */ 211 Get : function (objid) { 212 if (arguments.length > 1) { 213 for (var i = 0, objids = [], length = arguments.length; i < length; i++) 214 objids.push(this.Get(arguments[i])); 215 return objids; 216 } 217 if (typeof objid == 'string') 218 { 219 if (document.getElementById) { 220 objid = document.getElementById(objid); 221 } else if (document.all) { 222 objid = document.all[objid]; 223 } else if (document.layers) { 224 objid = document.layers[objid]; 225 } 226 } 227 return objid; 228 }, 229 230 /**//* 获取对象的值 231 @objid 对象ID 232 */ 233 GetValue : function (objid) { 234 if (typeof objid == 'string') 235 { 236 var getTagName = this.Get(objid).tagName.toLowerCase(); 237 if (getTagName == 'input' || getTagName == 'textarea' || getTagName == 'select') 238 { 239 return this.Get(objid).value; 240 } 241 else if (getTagName == 'div' || getTagName == 'span') 242 { 243 return this.Get(objid).innerText; 244 } 245 } 246 else if (typeof objid == 'object') 247 { 248 return objid.value; 249 } 250 }, 251 252 /**//* 设置指定对象的值,实现可以直接赋值或清除操作 253 @objid 对象ID 254 @inserValue 传入值(可选项 Null:清除该ID的值, 则直接赋值) 255 */ 256 SetValue: function(objid,inserValue) { 257 var getTagName = this.Get(objid).tagName.toLowerCase(); 258 if (inserValue == null) inserValue = ''; 259 if (getTagName == 'input' || getTagName == 'textarea') 260 { 261 this.Get(objid).value = inserValue; 262 } 263 else if (getTagName == 'div' || getTagName == 'sapn') 264 { 265 266 this.Get(objid).innerText = inserValue; 267 } 268 }, 269 270 /**//* 拷贝对象值到剪贴板 271 @str 对象值 272 */ 273 CopyCode : function (str) { 274 var rng = document.body.createTextRange(); 275 rng.moveToElementText(str); 276 rng.scrollIntoView(); 277 rng.select(); 278 rng.execCommand("Copy"); 279 rng.collapse(false); 280 }, 281 282 /**//* 显示隐藏一个对象 283 @Objid 对象ID 284 @isshow 具体操作,指定Obj为False : none或者True : block (可选) 285 */ 286 ShowHidd : function(objid,isshow){ 287 if (isshow != null) 288 { 289 if(isshow) 290 { 291 this.Get(objid).style.display = 'block'; 292 } 293 else 294 { 295 this.Get(objid).style.display = 'none'; 296 } 297 } 298 else 299 { 300 if(this.Get(objid).style.display == 'none') 301 { 302 this.Get(objid).style.display = 'block'; 303 } 304 else 305 { 306 this.Get(objid).style.display = 'none'; 307 } 308 } 309 }, 310 311 /**//* 当前对象是否可见 312 @objid 对象ID 313 */ 314 IsVisible : function(objid){ 315 if(this.Get(objid)) 316 { 317 try 318 { 319 if (this.Get(objid).style.display == 'none') 320 { 321 return false 322 } 323 if(this.Get(objid).style.visibility == 'hidden') 324 { 325 return false; 326 } 327 return true; 328 } 329 catch(e) 330 { 331 return false; 332 } 333 } 334 else 335 { 336 return false; 337 } 338 } 339}; 340 341/// 字符处理 342var Sams_string = { 343 /**//* 取左边的指定长度的值 344 @str 要处理的字符集 345 @n 长度 346 */ 347 Left : function (str,n) 348 { 349 if(str.length > 0) 350 { 351 if(n>str.length) n = str.length; 352 return str.substr(0,n) 353 } 354 else 355 { 356 return; 357 } 358 }, 359 360 /**//* 取右边的指定长度的值 361 @str 要处理的字符集 362 @n 长度 363 */ 364 Right : function (str,n) 365 { 366 if(str.length > 0) 367 { 368 if(n>=str.length) return str; 369 return str.substr(str.length-n,n); 370 } 371 else 372 { 373 return; 374 } 375 }, 376 377 /**//* Trim:清除两边空格 378 @str 要处理的字符集 379 */ 380 Trim : function (str) 381 { 382 if (typeof str == 'string') return str.replace(/(^s*)|(s*$)/g, ''); 383 }, 384 385 /**//* LTrim:清除左边的空格 386 @str 要处理的字符集 387 */ 388 Ltrim : function (str) 389 { 390 if (typeof str == 'string') return str.replace(/(^s*)/g, ''); 391 }, 392 393 /**//* RTrim: 清除右边的空格 394 @str 要处理的字符集 395 */ 396 Rtrim : function (str) 397 { 398 if (typeof str == 'string') return str.replace(/(s*$)/g, ''); 399 }, 400 401 /**//* 清除前后的非字符 402 @str 要处理的字符集 403 */ 404 strip : function(str) { 405 if (typeof str == 'string') return str.replace(/^s+/, '').replace(/(^s*)|(s*$)/g, ''); 406 }, 407 408 /**//* 过滤字符里面的HTML标签 409 @str 要处理的字符集 410 */ 411 stripTags : function(str) { 412 if (typeof str == 'string')return str.replace(/</?[^>]+>/gi, '').replace(/(^s*)|(s*$)/g, ''); 413 } 414}; 415 416/// 时间相关操作 417var Sams_time = { 418 /**//* 获取当天日期 yyyy-MM-dd */ 419 GetDateNow : function (){ 420 var d,y,m,dd; 421 d = new Date(); 422 y = d.getYear(); 423 m = d.getMonth() + 1; 424 dd = d.getDate(); 425 return y+"-"+m+"-"+dd; 426 }, 427 428 /**//* 获取指定日期后的特定天数的日期值 429 @toDate 当前指定的日期 430 @N 要添加的日期数 431 */ 432 AddDays : function(toDate,N){ 433 var aDate=this._cvtISOToDate(toDate); 434 if (!aDate) return ""; 435 var millis=86400000 * N; 436 aDate=new Date(aDate.getTime()+millis); 437 return this._fmtDateISO(aDate); 438 }, 439 _fmtDateISO : function (aDate) { 440 with (aDate) { 441 var mm=getMonth()+1; 442 if (mm<10) {mm='0'+mm;} 443 var dd=getDate(); 444 if (dd<10) {dd='0'+dd;} 445 return (getFullYear() + '-' + mm + '-' + dd); 446 } 447 }, 448 _cvtISOToDate : function (isoDate) { 449 var atomDate= isoDate.split('-'); 450 var aDate=new Date(parseInt(atomDate[0],10),parseInt(atomDate[1],10)-1,parseInt(atomDate[2],10),6,0,0); 451 return aDate; 452 } 453}; 454 455/// 图像相关操作 456var Sams_media = { 457 /**//* 为单一图像添加鼠标中键放大缩小功能, 批量可以直接用 ResizeImage(指定添加该功能的图片大小:Int) 即可 (该功能只适用于IE) 458 objid 对象ID 459 */ 460 ZoomFun : function(objid){ 461 Sams_object.Get(objid).onmousewheel = function(){return Sams_media.imagecontrol(this);} 462 }, 463 464 /**//* 重置图片尺寸同时添加放大功能 (该功能只适用于IE) 465 @IntSize 指定图像的大小 466 如果适合图像大小就添加放大缩小功能 467 */ 468 ResizeImage: function (IntSize) { 469 var imgsinlog=document.getElementsByTagName('img'); 470 for(j=0; j<imgsinlog.length; j++) { 471 if (imgsinlog[j].width >= IntSize) { 472 imgsinlog[j].width = IntSize; 473 imgsinlog[j].style.cursor= 'pointer'; 474 imgsinlog[j].onclick = function() {window.open(this.src);} 475 if (navigator.userAgent.toLowerCase().indexOf('ie') > -1) { 476 imgsinlog[j].title = '您可以用鼠标中键或者使用Ctrl+鼠标滚轮缩放图片,点击图片可在新窗口打开'; 477 imgsinlog[j].onmousewheel = function(){return Sams_media.imagecontrol(this);}; 478 } 479 else 480 { 481 imgsinlog[j].title = '点击图片可在新窗口打开'; 482 } 483 } 484 } 485 }, 486 imagecontrol : function(obj){ 487 var zoom=parseInt(obj.style.zoom, 10)||100;zoom+=event.wheelDelta/12; 488 if (zoom>0) obj.style.zoom=zoom+'%'; 489 return false; 490 }, 491 492 /**//* 如果图像出现下载不了等异常,显示的错误提示图片 493 @errimgpath 显示错误提示的图像路径 494 */ 495 ImagesError : function(errimgpath){ 496 var imglist = document.getElementsByTagName('img'); 497 for(j=0; j<imglist.length; j++) { 498 imglist[j].onerror = function(){ 499 this.src = errimgpath; 500 } 501 } 502 }, 503 504 /**//* 显示媒体 505 @mFile 文件路径 506 @mFileType 文件类型(可为空,如为Flash,要指定为swf类型) 507 @ObjID 对象ID 508 @mWidth 显示的对象宽度 509 @mHeight 显示对象的高度 510 注: 可以指定对象的ID, 如果ID不存在,会自动创建,追加在Body后面 511 */ 512 ShowMedia : function (mFile, mFileType, ObjID, mWidth, mHeight) { 513 var mediaStr; 514 switch(mFileType){ 515 case "swf": 516 mediaStr="<object codeBase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='"+mWidth+"' height='"+mHeight+"'><param name='movie' value='"+mFile+"'><param name='quality' value='high'><param name='AllowScriptAccess' value='never'><embed src='"+mFile+"' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='"+mWidth+"' height='"+mHeight+"'></embed></OBJECT>"; 517 break; 518 default : 519 mediaStr="<object width='"+mWidth+"' height='"+mHeight+"' classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6'><param name='url' value='"+mFile+"' /><embed width='"+mWidth+"' height='"+mHeight+"' type='application/x-mplayer2' src='"+mFile+"'></embed></object>"; 520 } 521 522 var mediaDiv = Sams_object.Get(ObjID); 523 524 if (mediaDiv) { 525 mediaDiv.innerHTML = mediaStr; 526 } 527 else 528 { 529 mediaDiv = document.createElement("div"); 530 mediaDiv.id = ObjID; 531 mediaDiv.innerHTML = mediaStr; 532 document.getElementsByTagName('body')[0].appendChild(mediaDiv); 533 } 534 return false; 535 } 536}; 537 538/// 样式相关操作 539var Sams_style = { 540 /**//* 改变字体大小 541 @objid 对象ID 542 @size 字号 543 */ 544 doZoom : function (objid,size){ 545 Sams_object.Get(objid).style.fontSize=size+'px'; 546 }, 547 548 /**//* 改变指定对象样式 549 @objid 对象ID 550 @className 要更改的ClassName 551 */ 552 ClassName: function(objid, className) { 553 Sams_object.Get(objid).className = className; 554 }, 555 556 /**//* 对象定位 557 @obj 要定位的对象 558 返回 X.Y 结果的数组对象 559 */ 560 GotoXY : function (obj) { 561 var t=obj.offsetTop; 562 var l=obj.offsetLeft; 563 while(obj=obj.offsetParent){ 564 t+=obj.offsetTop; 565 l+=obj.offsetLeft; 566 } 567 return Array(t,l); 568 } 569}; 570 571/// 科学计算 572var Sams_account = { 573 /**//* 逢1进10计算 574 @ 数值 575 */ 576 GetTen: function (i) 577 { 578 var items_One,Get_One; 579 if (i.length > 1&& (/^d+$/.test(i))) 580 { 581 items_One = i.substr(0,i.length-1); 582 Get_One = i.substr(i.length-1,1); 583 if (parseInt(Get_One)>0) 584 { 585 items_One = parseInt(items_One)+1; 586 items_One = items_One + '0'; 587 } 588 else 589 { 590 items_One = items_One + '0'; 591 } 592 } 593 else 594 { 595 items_One = i; 596 } 597 return items_One; 598 } 599}; 600 601/// 数据验证(所有数值返回值均为Bool型) 602var Sams_validate = { 603 /**//* 是否是数字型数据 604 @str 字符集 605 */ 606 IsNumber : function(str){ 607 if (/^d+$/.test(str)){return true;}else{return false;} 608 }, 609 610 /**//* 是否是数字型数据 611 @objid 对象ID 612 */ 613 IsNumberObj : function(objid){ 614 return this.IsNumber(Sams_object.GetValue(objid)); 615 }, 616 617 /**//* 是否是自然数型数据 618 @str 字符集 619 */ 620 IsInt : function(str){ 621 if (/^(+|-)?d+$/.test(str)){return true;}else{return false;} 622 }, 623 624 /**//* 是否是自然数型数据 625 @objid 对象ID 626 */ 627 IsIntObj : function(objid){ 628 return this.IsInt(Sams_object.GetValue(objid)); 629 }, 630 631 /**//* 是否是中文字符 632 @str 字符集 633 */ 634 IsChinese : function(str) 635 { 636 if (/^[u4e00-u9fa5]+$/.test(str)){return true;}else{return false;} 637 }, 638 639 /**//* 是否是中文字符 640 @objid 对象ID 641 */ 642 IsChineseObj : function(objid) 643 { 644 return this.IsChinese(Sams_object.GetValue(objid)); 645 }, 646 647 /**//* 是否为英文字母 648 @str 字符集 649 */ 650 IsLower : function(str) 651 { 652 if (/^[A-Za-z]+$/.test(str)){return true}else{return false;} 653 }, 654 655 /**//* 是否为英文字母 656 @objid 对象ID 657 */ 658 IsLowerObj : function(objid) 659 { 660 return this.IsLower(Sams_object.GetValue(objid)); 661 }, 662 663 /**//* 是否为正确的网址 664 @str 字符集 665 */ 666 IsUrl : function(str) 667 { 668 var myReg = /^((http:[/][/])?w+([.]w+|[/]w*)*)?$/; 669 if(myReg.test(str)){return true;}else{return false;} 670 }, 671 672 /**//* 是否为正确的网址 673 @objid 对象ID 674 */ 675 IsUrlObj : function(objid) 676 { 677 return this.IsUrl(Sams_object.GetValue(objid)); 678 }, 679 680 /**//* 是否为正确的Email形式 681 @str 字符集 682 */ 683 IsEmail : function(str) 684 { 685 var myReg = /^([-_A-Za-z0-9.]+)@([_A-Za-z0-9]+.)+[A-Za-z0-9]{2,3}$/; 686 if(myReg.test(str)){return true;}else{return false;} 687 }, 688 689 690 /**//* 是否为正确的Email形式 691 @objid 对象ID 692 */ 693 IsEmailObj : function(objid) 694 { 695 return this.IsEmail(Sams_object.GetValue(objid)); 696 }, 697 698 /**//* 是否为正确的手机号码 699 @str 字符集 700 */ 701 IsMobile : function(str) 702 { 703 var regu =/(^[1][3][0-9]{9}$)|(^0[1][3][0-9]{9}$)/; 704 var re = new RegExp(regu); 705 if (re.test(str)){return true;}else{return false;} 706 }, 707 708 /**//* 是否为正确的手机号码 709 @objid 对象ID 710 */ 711 IsMobileObj : function(objid) 712 { 713 return this.IsMobile(Sams_object.GetValue(objid)); 714 } 715}; 716 717/**//* 718 实现Ajax功能 719 Sams_ajax.SendRequest('GET', url, null, recall, "addtohome"); 720 Sams_ajax.SendRequest('GET', url, null, null); 721 obj.responseText; 722*/ 723var Sams_ajax = { 724 _objPool: [], 725 _getInstance: function (){ 726 for (var i = 0; i < this._objPool.length; i ++){ 727 if (this._objPool[i].readyState == 0 || this._objPool[i].readyState == 4){ 728 return this._objPool[i]; 729 } 730 } 731 this._objPool[this._objPool.length] = this._createObj(); 732 return this._objPool[this._objPool.length - 1]; 733 }, 734 _createObj : function (){ 735 if (window.XMLHttpRequest){ 736 var objXMLHttp = new XMLHttpRequest(); 737 } 738 else{ 739 var MSXML = ['MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP']; 740 for(var n = 0; n < MSXML.length; n ++){ 741 try{ 742 var objXMLHttp = new ActiveXObject(MSXML[n]); 743 break; 744 } 745 catch(e){ 746 } 747 } 748 } 749 if (objXMLHttp.readyState == null){ 750 objXMLHttp.readyState = 0; 751 objXMLHttp.addEventListener("load", function (){ 752 objXMLHttp.readyState = 4; 753 if (typeof objXMLHttp.onreadystatechange == "function"){ 754 objXMLHttp.onreadystatechange(); 755 } 756 }, false); 757 } 758 return objXMLHttp; 759 }, 760 761 /// 开始发送请求 762 SendRequest : function (method, url, data, callback,funparam,funparam2){ 763 var objXMLHttp = this._getInstance(); 764 with(objXMLHttp){ 765 try{ 766 if (url.indexOf("?") > 0){ 767 url += "&randnum=" + Math.random(); 768 } 769 else{ 770 url += "?randnum=" + Math.random(); 771 } 772 open(method, url, true); 773 setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); 774 send(data); 775 onreadystatechange = function (){ 776 if (objXMLHttp.readyState == 4 && (objXMLHttp.status == 200 || objXMLHttp.status == 304)) 777 { 778 callback(objXMLHttp,funparam,funparam2); 779 }else{ 780 callback(null,funparam,funparam2); 781 } 782 } 783 } 784 catch(e){ 785 alert(e); 786 } 787 } 788 } 789}; 790 791/// Cookies操作 792var Sams_cookies = { 793 /**//* cookies设置函数 794 @name Cookies名称 795 @value 值 796 */ 797 setCookie : function (name, value) 798 { 799 try 800 { 801 var argv = setCookie.arguments; 802 var argc = setCookie.arguments.length; 803 var expires = (argc > 2) ? argv[2] : null; 804 if(expires!=null) 805 { 806 var LargeExpDate = new Date (); 807 LargeExpDate.setTime(LargeExpDate.getTime() + (expires*1000*3600*24)); 808 } 809 document.cookie = name + "=" + escape (value)+((expires == null) ? "" : ("; expires=" +LargeExpDate.toGMTString())); 810 return true; 811 } 812 catch(e) 813 { 814 return false; 815 } 816 }, 817 818 /**//* cookies读取函数 819 @Name Cookies名称 820 返回值 Cookies值 821 */ 822 getCookie : function (Name) 823 { 824 var search = Name + "=" 825 if(document.cookie.length > 0) 826 { 827 offset = document.cookie.indexOf(search) 828 if(offset != -1) 829 { 830 offset += search.length 831 end = document.cookie.indexOf(";", offset) 832 if(end == -1) end = document.cookie.length 833 return unescape(document.cookie.substring(offset, end)) 834 } 835 else 836 { 837 return; 838 } 839 } 840 } 841};

  推荐阅读

  通过Unicode转义序列来加密,按你说的可以算是混淆吧

<script> test = "我来加个密玩玩,虽然是垃圾别见怪啊!" str = "" for( i=0; i<test.length; i++ ) { temp = test.charCodeAt(i).toString(16); str += "\u"+ new Array(5-String(temp).length).join("0>>>详细阅读


本文标题:(推荐一个超好的JS函数库)S.Sams Lifexperience ScriptClassLib

地址:http://www.17bianji.com/kaifa2/JS/30506.html

关键词: 探索发现

乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

网友点评
自媒体专栏

评论

热度

精彩导读
栏目ID=71的表不存在(操作类型=0)