func.js
上传用户:weisheen
上传日期:2022-07-09
资源大小:19390k
文件大小:6k
- //check all
- function selectNumOfCheckBox(oneBoxName){
- var oneBoxObj=document.getElementsByName(oneBoxName);
- var selectedNum=0;
- if (oneBoxObj){
- for(var i=0;i<oneBoxObj.length;i++){
- if(oneBoxObj[i].checked){
- selectedNum++;
- }
- }
- }
- return selectedNum;
- }
- function selectAllCheckbox(allBoxName,oneBoxName){
- var allBoxObj=document.getElementsByName(allBoxName)[0];
- var oneBoxObj=document.getElementsByName(oneBoxName);
- if (oneBoxObj){
- for(var i=0;i<oneBoxObj.length;i++){
- oneBoxObj[i].checked=allBoxObj.checked;
- }
- }
- }
- function selectOneCheckbox(allBoxName,oneBoxName){
- var allBoxObj=document.getElementsByName(allBoxName)[0];
- var oneBoxObj=document.getElementsByName(oneBoxName);
- var checkNum=selectNumOfCheckBox(oneBoxName);
- if (allBoxObj){
- if(oneBoxObj.length==checkNum){
- allBoxObj.checked=true;
- }
- else{
- allBoxObj.checked=false;
- }
- }
- }
- /*
- GetObjByName
- */
- function GetObjByName(objName){
- return document.getElementsByName(objName);
- }
- /*
- GetObjById
- */
- function GetObjById(objId){
- //alert(document.getElementById(objId));
- return document.getElementById(objId);
- }
- /*
- GetValueById
- */
- function GetValueById(objId){
- return document.getElementById(objId).value;
- }
- /*
- replaceAll in javascript
- */
- String.prototype.replaceAll = function(search, replace){
- var regex = new RegExp(search, "g");
- return this.replace(regex, replace);
- }
- /*
- replace left and right space
-
- */
- String.prototype.Trim= function(){
- return this.replace(/(^s*)|(s*$)/g, "");
- }
- /*
- count string length of byte
- */
- String.prototype.Lenb = function() {
- return this.replace(/[^x00-xff]/g,"**").length;
- }
- /*
- check String make up of number and char
- */
-
- function CheckTextInNumAndChar(str){
- var thePattern=/^[A-Za-z0-9]*?$/;
- var retValue=thePattern.test(str);
- return retValue;
- }
- /*
- check String make up of number
- */
- function CheckTextInNumber(str){
- var thePattern=/^d*?$/;
- var retValue=thePattern.test(str);
- return retValue;
- }
- /*
- check email
- */
- function checkEmailExist(emailStr){
- var regexp = /^[a-zA-Z0-9_.]+@[a-zA-Z0-9-]+[.a-zA-Z]+$/;
- return regexp.test(emailStr);
- }
- function chkPhoneExist(phoneStr){
- if(phoneStr=="" || phoneStr==null){
- return false;
- }
- var phReg = /^(([0+]d{2,3}-)?(0d{2,3})-)?(d{5,12})(-(d{3,}))?$/;
- return phReg.test(phoneStr);
- }
- /*
- check email
- /^([A-Za-z0-9])(w)+@(w)+(.)(com|com.cn|net|cn|net.cn|org|biz|info|gov|gov.cn|edu|edu.cn)$/;
- /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(.[a-zA-Z0-9_-]+)+$/;
- /^d{4}-(0?[1-9]|1[0-2])-(0?[1-9]|[1-2]d|3[0-1])$/;
- /^[a-zA-Z0-9_-.]+@+[a-zA-Z0-9_-]+[.]+[com|com.cn|net|cn|net.cn|org|biz|info|gov|gov.cn|edu|edu.cn]/
- */
- function checkEmail(str){
- var reEml =/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(.[a-zA-Z0-9_-]+)+$/;
- var isOk=reEml.test(str);
- alert(isOk);
- return isOk;
- }
- /*
- SubString in javascript
- */
- function JsSubString(OldString,maxLength){
- var OldStringLength=OldString.length;
- if(OldStringLength<=0){
- return OldString;
- }
- if(isNaN(maxLength)){
- return OldString;
- }
- var retString="";
- if (OldString.Lenb()<=maxLength){
- return OldString;
- }
- else{
- for(var i=0;i<OldStringLength;i++){
- if(retString.Lenb()>=maxLength){
- break;
- }
- else{
- retString+=OldString.charAt(i);
- }
- }
- return retString;
- }
- }
- /*
- check input textradiocheckboxTextarea input is true
- inputName
- inputType
- maxLength
- minLength
- emNull
- emType
-
-
-
- */
- function CheckInputText(inputName,inputType,maxLength,minLength,emNull,emType){
- if (allowType=="") {
- return false;
- }
- return true;
-
- }
- String.prototype.StringToDateValue=function (){
- var DateArr=this.split("-");
- if (DateArr.length!=3){
- return "0";
- }
- var theDate=new Date(DateArr[0],DateArr[1],DateArr[2]);
- return theDate.getTime();
- }
- function getCookie(cName){
- var cookieStr=document.cookie;
- var cookieArr=cookieStr.split("; ");
- var cookieLen=cookieArr.length;
- var oneCkStr="";
- var theValue="";
- var oneArr;
- for (var tmp_ii=0;tmp_ii<cookieLen;tmp_ii++){
- oneCkStr=cookieArr[tmp_ii];
- oneArr=oneCkStr.split("=");
- if (cName==oneArr[0]){
- theValue=oneArr[1];
- break;
- }
- }
- return theValue;
- }
- function setCookie(cookieName,cookieValue,days){
- var expire = "";
- if (days!=0){
- expire = new Date((new Date()).getTime() + days * 24 * 3600000);
- expire = "expires=" + expire.toGMTString() + ";" ;
- }
- path = "; path=/";
- document.cookie = cookieName + "=" + escape(cookieValue) + ";" + expire + path;
- }
- String.prototype.replaceAll = function(search, replace){
- var regex = new RegExp(search, "g");
- return this.replace(regex, replace);
- }
- var Request = new function(){
- this.pool = new Array();
- this.getXMLHttp = function (){
- for (var i = 0; i < this.pool.length; i++){
- if (this.pool[i]["obj"].readyState == 0 || this.pool[i]["obj"].readyState == 4){
- return this.pool[i]["obj"];
- }
- }
- this.pool[this.pool.length] = new Array();
- this.pool[this.pool.length - 1]["obj"] = this.createXMLHttp();
- return this.pool[this.pool.length - 1]["obj"];
- }
- this.createXMLHttp = function (){
- if(window.XMLHttpRequest){
- var xmlObj = new XMLHttpRequest();
- }
- else{
- var MSXML = ['Microsoft.XMLHTTP', 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP'];
- for(var n = 0; n < MSXML.length; n++){
- try{
- var xmlObj = new ActiveXObject(MSXML[n]);
- break;
- }catch(e){}
- }
- }
- return xmlObj;
- }
- this.reSend = function (url,data,callback){
- var objXMLHttp = this.getXMLHttp()
- if(typeof(objXMLHttp) != "object"){
- return ;
- }
- url += (url.indexOf("?") >= 0) ? "&random=" + new Date().getTime() : "?random=" + new Date().getTime();
- // alert(url);
- if(data == ""){
- objXMLHttp.open('GET' , url, true);
- objXMLHttp.send('');
- }
- else{
- objXMLHttp.open('POST' , url, true);
- objXMLHttp.setRequestHeader("Content-Length",data.length);
- objXMLHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
- objXMLHttp.send(data);
- }
- if(typeof(callback) == "function" ){
- objXMLHttp.onreadystatechange = function (){
- if (objXMLHttp.readyState == 4){
- if(objXMLHttp.status == 200 || objXMLHttp.status == 304){
- callback(objXMLHttp);
- }
- else{
-
- }
- objXMLHttp.abort();
- }
- }
- }
- }
- }