您的位置:首页 > Web前端 > JavaScript

常用的脚本验证 js

2006-12-25 21:04 519 查看
/*
 公用js 函数
 */
   // 允许上传的图片扩展名
var picExt = "JPEG|JPG|BMP|GIF|TIF|PNG|ICO|";
   // 允许上传的文件扩展名
var fileAllowExt = "DOC|XLS|PPT|PPS|PDF|RAR|ZIP|VSD|JPEG|JPG|BMP|GIF|TIF|PNG|ICO|AVI|MIDI|MOV|WMA|RM|MP3|SWF|TXT|";
//提醒间隔周期.
var txzq=1000*5*100;
/*
 返回字符串的字节数 一个汉字是2个字节  
 */
function getStrBytes(varStr) {
 var count = 0;
 for (var i = 0; i < varStr.length; i++) {
  if (varStr.charCodeAt(i) > 127 || varStr.charCodeAt(i) == 94) {
   count = count + 2;
  } else {
   count = count + 1;
  }
 }
 return count;
}
/*
 电话号码验证
*/
function chkTEL(tel) {
 var i, j, strTemp;
 strTemp = "0123456789-()#+ ";
 for (i = 0; i < tel.length; i++) {
  j = strTemp.indexOf(tel.charAt(i));
  if (j == -1) {
   return false;
  }
 }
 return true;
}
/*
 Email验证
*/
function chkemail(a) {
 return //w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*/.test(a);
 /*
 var i=a.length;
 var temp = a.indexOf('@');
 var tempd = a.indexOf('.');
 if (temp > 1)
  if ((i-temp) > 3)
   if ((i-tempd)>0)  return true;
 return false;*/
}
/*url校验*/
function validateURL(url){
 var urlpatern1 =/^https?:////(([a-zA-Z0-9_-])+(/.)?)*(:/d+)?(//((/.)?(/?)?=?&?[a-zA-Z0-9_-](/?)?)*)*$/i;
 if(!urlpatern1.test(url)){
 return  false;
 }
 return true;
}
/*
 日期检查   idDate(str)
*/
/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh = "-";
var minYear = 1900;
var maxYear = 2100;
function isInteger(s) {
 var i;
 for (i = 0; i < s.length; i++) {  
        // Check that current character is number.
  var c = s.charAt(i);
  if (((c < "0") || (c > "9"))) {
   return false;
  }
 }
    // All characters are numbers.
 return true;
}
function stripCharsInBag(s, bag) {
 var i;
 var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
 for (i = 0; i < s.length; i++) {
  var c = s.charAt(i);
  if (bag.indexOf(c) == -1) {
   returnString += c;
  }
 }
 return returnString;
}
function daysInFebruary(year) {
 // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
 return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
}
function DaysArray(n) {
 for (var i = 1; i <= n; i++) {
  this[i] = 31;
  if (i == 4 || i == 6 || i == 9 || i == 11) {
   this[i] = 30;
  }
  if (i == 2) {
   this[i] = 29;
  }
 }
 return this;
}
function isDate(dtStr) {
 var result = dtStr.match(/^(/d{4})(-)(/d{2})(-)(/d{2})$/);
 if (result == null) {
  return false;
 }
 var daysInMonth = DaysArray(12);
 var pos1 = dtStr.indexOf(dtCh);
 var pos2 = dtStr.indexOf(dtCh, pos1 + 1);
 var strMonth = dtStr.substring(pos1 + 1, pos2);
 var strDay = dtStr.substring(pos2 + 1);
 var strYear = dtStr.substring(0, pos1);
 
 //var strMonth=dtStr.substring(0,pos1)
 //var strDay=dtStr.substring(pos1+1,pos2)
 //var strYear=dtStr.substring(pos2+1)
 strYr = strYear;
 if (strDay.charAt(0) == "0" && strDay.length > 1) {
  strDay = strDay.substring(1);
 }
 if (strMonth.charAt(0) == "0" && strMonth.length > 1) {
  strMonth = strMonth.substring(1);
 }
 for (var i = 1; i <= 3; i++) {
  if (strYr.charAt(0) == "0" && strYr.length > 1) {
   strYr = strYr.substring(1);
  }
 }
 month = parseInt(strMonth);
 day = parseInt(strDay);
 year = parseInt(strYr);
 if (pos1 == -1 || pos2 == -1) {
  //alert("The date format should be : mm/dd/yyyy")
  return false;
 }
 if (strMonth.length < 1 || month < 1 || month > 12) {
  //alert("Please enter a valid month")
  return false;
 }
 if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month]) {
  //alert("Please enter a valid day")
  return false;
 }
 if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear) {
  //alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
  return false;
 }
 if (dtStr.indexOf(dtCh, pos2 + 1) != -1 || isInteger(stripCharsInBag(dtStr, dtCh)) == false) {
  //alert("Please enter a valid date")
  return false;
 }
 return true;
}
/*
 del head and end space
*/
function strTrim(str) {
 return str.replace(/(^/s*)|(/s*$)/g, "");
}
/*
 
*/
function isDigit(s) {
 return (s.replace(//d/g, "").length == 0);
}
/*
 
*/
function isAlpha(s) {
 return (s.replace(//w/g, "").length == 0);
}
/*
 
*/
function isNumber(s) {
 return (s.search(/^[+-]?[0-9.]*$/) >= 0);
}
/*
 
*/
function lenb(s) {
 return s.replace(/[^/x00-/xff]/g, "**").length;
}
/*
 是否包含汉字
*/
function isInChinese(s) {
 return (s.length != s.replace(/[^/x00-/xff]/g, "**").length);
}
function nextFgf(url){
  if (url==null) return "";
  if(url.indexOf("?")==-1){
   return "?";
  }
  return "&";
}
/*
 if class="inputred" then is must not empty
*/
function checkForm(fm) {
 var firstele;
 var form = document.getElementById(fm);
 var eles = new Array();
 var rtn = true;
 var formels = form.elements;
 for (var i = 0; i < formels.length; i++) {
  var element = formels[i];
  if (element.type == "text" || element.type == "textarea" || element.type == "select-one" || element.type == "password") {
   eles[eles.length] = formels[i];
  }
 }
 for (var i = 0; i < eles.length; i++) {
  var ele = eles[i];
  var value = ele.value;
  //上一级元素
  var po = ele.parentElement;
     //清除前一次做的标记
  checkFormClear(po, ele);
  if(ele.disabled==true){
   continue;
  }
     //必须验证
  if (ele.className == "inputred" || ele.request=="true") {
   if (strTrim(value).length == 0) {
    checkFormChange(po, ele, 1, "");
    if (!firstele) {
     firstele = ele;
    }
   }
  }
  var maxlen = ele.getAttribute("maxlength");
  if (maxlen != "" && maxlen != null) {
   if (lenb(value) > maxlen) {
    checkFormChange(po, ele, 2, maxlen);
    if (!firstele) {
     firstele = ele;
    }
   }
  }
  var minlen = ele.getAttribute("minlength");
  if (minlen != "" && minlen != null) {
   if (lenb(value) < minlen) {
    checkFormChange(po, ele, 4, minlen);
    if (!firstele) {
     firstele = ele;
    }
   }
  }
  var greatethan = ele.getAttribute("greatethan");
  if (greatethan != "" && greatethan != null) {
    
   if (value!="" && parseFloat(value) < greatethan) {
    checkFormChange(po, ele, 5, greatethan);
    if (!firstele) {
     firstele = ele;
    }
   }
  }
  var lessthan = ele.getAttribute("lessthan");
  if (lessthan != "" && lessthan != null) {
  
   if (value!="" && parseFloat(value) > lessthan) {
    checkFormChange(po, ele, 6, lessthan);
    if (!firstele) {
     firstele = ele;
    }
   }
  }  
  //格式验证
  var ctype = ele.getAttribute("ctype");
  if (ctype != "" && value != "") {
   switch (ctype) {
     case "date":
    if (!isDate(value)) {
     checkFormChange(po, ele, 3, "/u8bf7/u8f93/u5165/u6b63/u786e/u7684/u65e5/u671f/u683c/u5f0f/u4e3a yyyy-mm-dd/uff01");
     if (!firstele) {
      firstele = ele;
     }
    }
    break;
     case "email":
    if (!chkemail(value)) {
     checkFormChange(po, ele, 3, "/u8bf7/u8f93/u5165/u6b63/u786e/u7684Email/u5730/u5740/uff0c/u4ee5/u65b9/u4fbf/u548c/u60a8/u8054/u7cfb/uff01");
     if (!firstele) {
      firstele = ele;
     }
    }
    break;
     case "digit":
    if (!isDigit(value)) {
     checkFormChange(po, ele, 3, "/u8bf7/u8f93/u51650/u52309/u4e4b/u95f4/u7684/u6570/u5b57/uff01");
     if (!firstele) {
      firstele = ele;
     }
    }
    break;
     case "number":
    if (!isNumber(value)) {
     checkFormChange(po, ele, 3, "/u8bf7/u8f93/u5165/u6b63/u786e/u7684/u6570/u5b57/uff01");
     if (!firstele) {
      firstele = ele;
     }
    }
    break;
     case "telephone":
    if (!chkTEL(value)) {
     checkFormChange(po, ele, 3, "/u8bf7/u8f93/u5165/u6b63/u786e/u7684/u7535/u8bdd/u53f7/u7801/uff01");
     if (!firstele) {
      firstele = ele;
     }
    }
    break;
   case "url":
    if (!validateURL(value)) {
     checkFormChange(po, ele, 3, "请输入正确的URL,URL必须以http开始.");
     if (!firstele) {
      firstele = ele;
     }
    }
    break;
    
   }
  }
 }
 if (firstele) {
 //重新定位
  var ddname;
  if (firstele.name == null || firstele.name == "") {
   ddname = firstele.id;
  } else {
   ddname = firstele.name;
  }
  document.getElementById(ddname).focus();
  if (document.getElementById(ddname).type != "select-one") {
   document.getElementById(ddname).select();
  }
  rtn = false;
 } else {
  rtn = true;
 }
 return rtn;
}
// BORDER-BOTTOM: #ff7300 1px solid;
var wrongstyle="PADDING-RIGHT: 3px;; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; MARGIN: 0px;  LINE-HEIGHT: 130%; PADDING-TOP: 3px; TEXT-ALIGN: left"
function checkFormChange(po, input, bz, str) {
 var span = "";
 if (bz == "1") {
  span = " /u6b64/u9879/u4e3a/u5fc5/u586b!";
 }
 if (bz == "2") {
  span = " /u60a8/u8f93/u5165/u7684/u5185/u5bb9/u4e0d/u80fd/u8d85/u8fc7/u89c4/u5b9a/u957f/u5ea6 " + str + " /u4e2a/u5b57/u8282/uff01";
 }
 if(bz=="4"){
  span="输入的字符数不能少于"+str+"个.";
 }
 if (bz == "3") {
  span = str;
 }
 if (bz=="5"){
  span="请输入大于 "+str+" 的值.";
 }
 if (bz=="6"){
  span="请输入小于于 "+str+" 的值.;";
 } 
 var ddname;//针对name为空的.
 if (input.name == null || input.name == "") {
  ddname = input.id;
 } else {
  ddname = input.name;
 }
 if (po != null) {
  var spanO = document.getElementById("textspan" + ddname);
    
     //已经存在 显示的span
  //try{
  if (spanO != null && spanO != "undefined") {
   spanO.innerHTML =  "<br><img
109d2
src='/images/icon_noteawake_16x16.gif' /> " + span;
  } else {
   span = "  <span style='"+wrongstyle+"' id='textspan" + ddname + "'>" + "<br><img src='/images/icon_noteawake_16x16.gif' /> " + span + "</span> ";
   po.innerHTML = po.innerHTML + span;
  }
  po.style.backgroundColor = "fff5d8"; 
  //}catch(e){} 
 }
}
function checkFormClear(po, input) {
 var ddname;
 if (input.name == null || input.name == "") {
  ddname = input.id;
 } else {
  ddname = input.name;
 }
 //try{
 var span = document.getElementById("textspan" + ddname);
 if (span != null && span != "undefined") {
  span.innerHTML = "";
 }
 if (po != null && po != "undefined") {
  po.style.backgroundColor = "";
 }
 //}catch(e){ }
}
/*
收藏夹 需要在页面定义一个隐含的元素<div id="favorite" style="display:none"></div>
*/
function favorite(lb, bt, surl) {
    // document.open();
 var favorite = document.getElementById("favorite");
 var html = "";
 html = "<form name='favorite' method='post' action='/favorite.shtml' target='_blank'>" + "<input type='hidden' name='lb' value='" + lb + "'>" + "<input type='hidden' name='bt' value='" + bt + "'>" + "<input type='hidden' name='surl' value='" + surl + "'>" + "</form>";
 favorite.innerHTML = html;
  //document.write(html);
 document.favorite.submit();
  //document.close();
}
function winopen(url, w, h) {
 OWinID = window.open(url, "", "toolbar=no,width=" + w + ",height=" + h + ",top=200 left=300 directories=no,status=no,scrollbars=no,resizable=no,menubar=no");
 OWinID.focus();
}
function vopen(url, name, w, h) {// if (! OWinID || OWinID.closed)
    if(w==null||w==""){w=800;}
    if(h==null||h==""){h=500;}
    var top,left;
    var pws=getPageSize();
    top=(pws[5]-h)/2 -20;
    left=(pws[4]-w)/2;
   // getPageSizenew Array(pageWidth,pageHeight,windowWidth,windowHeight,screen_width,screen_height)
 OWinID = window.open(url, name, "height=" + h + ",width=" + w + ",top="+top+",left="+left+",toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=yes");
 OWinID.focus();
}
function showMD(url,name,w,h){
 return window.showModalDialog(url,name,"dialogWidth:"+w+"px; dialogHeight:"+h+"px; directories:no; localtion:no; menubar:no; status:no; toolbar:no; scrollbars:no; resizeable:no;");
}
/*取得扩展名*/
function getFileExt(fileName) {
 var fileExt = fileName.substr(fileName.lastIndexOf(".") + 1).toUpperCase();
 return fileExt;
}
/*判断是否为图片*/
function isPicFile(fileName) {
 var fileExt = getFileExt(fileName) + "|";
 if (fileExt != "" && picExt.indexOf(fileExt) != -1) {
  return true;
 }
 return false;
}
/*判断是否为允许的文件扩展名*/
function isAllowFile(fileName) {
 var fileExt = getFileExt(fileName) + "|";
 if (fileAllowExt.indexOf(fileExt) != -1) {
  return true;
 }
 return false;
}
/*上传文件
 level 等级 如果是图片那么大小不能超过500k  其他的根据等级来判断
 一级 =< 2M
 二级 =<5M
 三级 =<20M
 四级 不限。
 field 要加入的字段 如果isDispaly  为false 直接加入相对根目录的路径 如果为false 将判断是否为图片或档案
 isDisplay 是否显示
 
*/
function upLoadFile(level, field, isDisplay) {
 var hh = window.showModalDialog("/webcontent/upload/uploadFile.jsp?level=" + level, "", "dialogWidth:600px; dialogHeight:300px; directories:no; localtion:no; menubar:no; status:no; toolbar:no; scrollbars:no; resizeable:no;");
 if (hh == "undefined" || hh == null || hh == "") {
  return;
 }
 var startIndex = hh.lastIndexOf("|");
 var sleft = "/" + hh.substring(0, startIndex);
 var jjjk = hh.lastIndexOf("|") + 1;
 var sright = hh.substring(jjjk, hh.length);
 var s = sleft;
 if (isDisplay) {
     //如果是图片    
  if (isPicFile(sleft)) {
   s = "<img src='" + sleft + "' alt='" + sright + "'>";
  } else {
        //flash动画
   if (getFileExt(sleft) == "SWF") {
    s = "<object classid=/"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000/" codebase=/"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0/" width=/"360/" height=/"78/">" + "<param name=/"movie/" value=/"" + sleft + "/">" + "<param name=/"quality/" value=/"high/">" + "<embed src=/"" + sleft + "/" quality=/"high/" pluginspage=/"http://www.macromedia.com/go/getflashplayer/" type=/"application/x-shockwave-flash/" width=/"360/" height=/"78/"></embed>" + "</object>";
   } else {
    s = "<A href='" + sleft + "'>" + sright + "</A>";
   }
  }
  var oEditor = FCKeditorAPI.GetInstance(field);
  if (oEditor.EditMode == FCK_EDITMODE_WYSIWYG) {
   oEditor.InsertHtml(s);
  } else {
   alert("You must be on WYSIWYG mode!");
  }
 }
 document.getElementById(field).value = s;
}
//弹出 已经存在的文件窗口
function addFile(field, isDisplay, accid, ishref) {
 var hh = window.showModalDialog("/uploadListForAccid.shtml", "", "dialogWidth:740px; dialogHeight:600px; directories:no; localtion:no; menubar:no; status:no; toolbar:no; scrollbars:no; resizeable:no;");
 if (hh == "undefined" || hh == null || hh == "") {
  return;
 }
 var sleft = "/acc/" + accid + "/ownUploadFiles/" + hh;
 var sright = hh;
 var s = sleft;
 if (isDisplay) {
     //如果是图片    
  if (isPicFile(sleft) && !ishref) {
   s = "<img src='" + sleft + "' alt='" + sright + "'>";
  } else {
        //flash动画
   if (getFileExt(sleft) == "SWF" && !ishref) {
    s = "<object classid=/"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000/" codebase=/"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0/" width=/"360/" height=/"78/">" + "<param name=/"movie/" value=/"" + sleft + "/">" + "<param name=/"quality/" value=/"high/">" + "<embed src=/"" + sleft + "/" quality=/"high/" pluginspage=/"http://www.macromedia.com/go/getflashplayer/" type=/"application/x-shockwave-flash/" width=/"360/" height=/"78/"></embed>" + "</object>";
   } else {
    s = "<A href='" + sleft + "'>" + sright + "</A>";
   }
  }
  var oEditor = FCKeditorAPI.GetInstance(field);
  if (oEditor.EditMode == FCK_EDITMODE_WYSIWYG) {
   oEditor.InsertHtml(s);
  } else {
   alert("You must be on WYSIWYG mode!");
  }
 }
 document.getElementById(field).value = s;
}
/*搜索结果加颜色  key 为关键字 colorKey 为要加颜色的内容标记*/
function colorKey(key) {
 if (key != "") {
  var keys = document.getElementsByName("colorKey");
  for (var i = 0; i < keys.length; i++) {
   var str = keys[i].innerHTML;
   var startPos = 0;
   var endPos = str.indexOf(key);
   var newStr = "";
   while (endPos != -1) {
    newStr = newStr + str.substring(startPos, endPos) + "<span class='colorKey'>" + key + "</span>";
    startPos = endPos + key.length;
    endPos = str.indexOf(key, startPos);
   }
   newStr = newStr + str.substring(startPos);
   keys[i].innerHTML = newStr;
  }
 }
}
/*
用来弹出选择数据字典类别
lb  数据字典的类别
lx  是选第一级还是二级 lx=1只选第一级分类,lx=2选择第二级分类
sfield1  要返回的第一个值
sfield2  要返回的第二个值
sfield3  要返回的第三个值
sfield4  要返回的第四个值
*/
function setClass(lb, lx, sfield1, sfield2, sfield3, sfield4) {
 var kk = "/b_classPopSele.shtml?lb=" + lb + "&lx=" + lx;
 var hh = window.showModalDialog(kk, "", "dialogWidth:300px; dialogHeight:450px; directories:no; localtion:no; menubar:no; status:no; toolbar:no; scrollbars:no; resizeable:no;");
 if (hh == "undefined" || hh == null || hh == "") {
  return;
 }
 var k = new Array();
 k = hh.split("|");
 if (lx == "1") {
  document.getElementById(sfield1).value = k[0];
  document.getElementById(sfield2).value = k[1];
 }
 if (lx == "2") {
  document.getElementById(sfield1).value = k[0];
  document.getElementById(sfield2).value = k[1];
  document.getElementById(sfield3).value = k[2];
  document.getElementById(sfield4).value = k[3];
 }
}
//$快捷 取对象函数
var $;
if (!$ && document.getElementById) {
  $ = function() {
    var elements = new Array();
    for (var i = 0; i < arguments.length; i++) {
      var element = arguments[i];
      if (typeof element == 'string') {
        element = document.getElementById(element);
      }
      if (arguments.length == 1) {
        return element;
      }
      elements.push(element);
    }
    return elements;
  }
}
else if (!$ && document.all) {
  $ = function() {
    var elements = new Array();
    for (var i = 0; i < arguments.length; i++) {
      var element = arguments[i];
      if (typeof element == 'string') {
        element = document.all[element];
      }
      if (arguments.length == 1) {
        return element;
      }
      elements.push(element);
    }
    return elements;
  }
}
/*屏幕尺寸*/
 function getPageSize(){
 var xScroll, yScroll;
 if (window.innerHeight && window.scrollMaxY) {
  xScroll = document.body.scrollWidth;
  yScroll = window.innerHeight + window.scrollMaxY;
 } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
  xScroll = document.body.scrollWidth;
  yScroll = document.body.scrollHeight;
 } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
  xScroll = document.body.offsetWidth;
  yScroll = document.body.offsetHeight;
 }
 var windowWidth, windowHeight;
 if (self.innerHeight) { // all except Explorer
  windowWidth = self.innerWidth;
  windowHeight = self.innerHeight;
 } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
  windowWidth = document.documentElement.clientWidth;
  windowHeight = document.documentElement.clientHeight;
 } else if (document.body) { // other Explorers
  windowWidth = document.body.clientWidth;
  windowHeight = document.body.clientHeight;
 }
// for small pages with total height less then height of the viewport
 if(yScroll < windowHeight){
  pageHeight = windowHeight;
 } else {
  pageHeight = yScroll;
 }
// for small pages with total width less then width of the viewport
 if(xScroll < windowWidth){
  pageWidth = windowWidth;
 } else {
  pageWidth = xScroll;
 }
 var screen_height = window.screen.availHeight;
 var screen_width = window.screen.availWidth;
 arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight,screen_width,screen_height);
 return arrayPageSize;
}
function rwin(){
 var pageSize=getPageSize();
 var pw=pageSize[0],ph=pageSize[1],ww=pageSize[2],wh=pageSize[3],sw=pageSize[4],sh=pageSize[5];
 var rw=pw+20,rh=ph+20;
 if(rh>700) {rh=700 ;};
 window.resizeTo(rw,rh); 
 //window.moveTo((sw-pw)/2,(sh-ph)/2-10);
 window.focus();
 
}
/*获得下拉框的显示值*/
function  opText(selObj,rv){
   /*如果值为空*/
   if(rv){
    if(selObj.options[selObj.selectedIndex].value==""){
     return "";
    }
   }
 return selObj.options[selObj.selectedIndex].text;
}
/******************************************/
/*功能:覆盖alert       */ 
/*                                        */
/*参数:string                             */
/*返回:无                                 */
/******************************************/

function aalert(str){
 var msgw,msgh,bordercolor;
 msgw=400;//提示窗口的宽度
 msgh=100;//提示窗口的高度
 titleheight=25 //提示窗口标题高度
 bordercolor="#336699";//提示窗口的边框颜色
 titlecolor="#99CCFF";//提示窗口的标题颜色
 
 var sWidth,sHeight;
 sWidth=document.body.clientWidth;
 sHeight=document.body.clientHeight;

 var bgObj=document.createElement("div");
 bgObj.setAttribute('id','bgDiv');
 bgObj.style.position="absolute";
 bgObj.style.top="0";
 bgObj.style.background="#777";
 bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
 bgObj.style.opacity="0.6";
 bgObj.style.left="0";
 bgObj.style.width=sWidth + "px";
 bgObj.style.height=sHeight + "px";
 bgObj.style.zIndex = "10000";
 document.body.appendChild(bgObj);
 
 var msgObj=document.createElement("div")
 msgObj.setAttribute("id","msgDiv");
 msgObj.setAttribute("align","center");
 msgObj.style.background="white";
 msgObj.style.border="1px solid " + bordercolor;
    msgObj.style.position = "absolute";
    msgObj.style.left = "50%";
    msgObj.style.top = "50%";
    msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
    msgObj.style.marginLeft = "-225px" ;
    msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px";
    msgObj.style.width = msgw + "px";
    msgObj.style.height =msgh + "px";   
    msgObj.style.textAlign = "center";
    msgObj.style.lineHeight ="25px";
    msgObj.style.zIndex = "10001";
 msgObj.style.padding = "0 0 20px 0";
   var title=document.createElement("h4");
   title.setAttribute("id","msgTitle");
   title.setAttribute("align","right");
   title.style.margin="0";
   title.style.padding="3px";
   title.style.background=bordercolor;
   title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
   title.style.opacity="0.75";
   title.style.border="1px solid " + bordercolor;
   title.style.height="18px";
   title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";
   title.style.color="white";
   title.style.cursor="pointer";
   title.innerHTML="关闭";
//   msgObj.onclick=
   document.body.appendChild(msgObj);
   document.getElementById("msgDiv").appendChild(title);
   var txt=document.createElement("p");
   txt.style.margin="1em 0"
   txt.setAttribute("id","msgTxt");
   txt.innerHTML=str;
         document.getElementById("msgDiv").appendChild(txt);
             var combutton=document.createElement("button");
     combutton.innerText="确定";
     combutton.onclick=function alertclose(){
        document.body.removeChild(bgObj);
              document.getElementById("msgDiv").removeChild(title);
              document.body.removeChild(msgObj);
              };
     combutton.className="ButtonBL";
     combutton.href="#";
     msgObj.appendChild(combutton);  
}
/*日期相加  addDate("2006-12-13","08:10","17");*/           
function addDate(A,B,C){
  var y,m,d,h,mm;
  y=A.substr(0,4);
  m=A.substr(5,2);
  d=A.substr(8,2);
  h=B.substr(0,2);
  mm=B.substr(3,2);
  var D=new Date(new Date(y,m-1,d,h,mm).getTime()+parseInt(C)*60*60*1000);
  
  y=D.getYear();
  m=D.getMonth()+1;
  if(m<10){
   m="0"+m;
  }
  d=D.getDate();
  if(d<10){
    d="0"+d;
  }
  h=D.getHours() ;
  if(h<10){
    h="0"+h;  
  }
  mm=D.getMinutes() ;
  if(mm<10){
    mm="0"+mm;
  }
  var rnt=y+"-"+m+"-"+d+" "+h+":"+mm+":"+"00";
  alert(rnt);
  return rnt;
  
 }
 /*使区域中的输入框不能提交修改*/
 function disabledTable(areaqy){
    try{
  var table=$(areaqy);
  var inputs=table.getElementsByTagName("input");
  for(var i=0;inputs!=null&&i<inputs.length;i++){
   inputs[i].setAttribute("disabled","disabled");
  }
  var selects=table.getElementsByTagName("select");
  for(var i=0;selects!=null&&i<selects.length;i++){
   selects[i].setAttribute("disabled","disabled");
  }
  var textareas=table.getElementsByTagName("textarea");
  for(var i=0;textareas!=null&&i<textareas.length;i++){
   textareas[i].setAttribute("disabled","disabled");
  }
  }catch(ex){}
 }
 /*使区域中的输入框能提交修改*/
 function openTable(areaqy){
   try{
  var table=$(areaqy);
  var inputs=table.getElementsByTagName("input");
  for(var i=0;inputs!=null&&i<inputs.length;i++){
   inputs[i].removeAttribute("disabled");
  }
  var selects=table.getElementsByTagName("select");
  for(var i=0;selects!=null&&i<selects.length;i++){
   selects[i].removeAttribute("disabled");
  }
  var textareas=table.getElementsByTagName("textarea");
  for(var i=0;textareas!=null&&i<textareas.length;i++){
   textareas[i].removeAttribute("disabled");
  }
  }catch(ex){}
 }
 //close
function cclose(){
 try{
  opener.focus();
 }catch(ex){}
 window.close();

//iframe 自动定高
  function iframeAutoFit()
    {
        try
        {
            if(window!=parent)
            {
                var a = parent.document.getElementsByTagName("IFRAME");
                for(var i=0; i<a.length; i++) //author:meizz
                {
                    if(a[i].contentWindow==window)
                    {
                        var h1=0, h2=0;
                        a[i].parentNode.style.height = a[i].offsetHeight +"px";
                        a[i].style.height = "10px";
                        if(document.documentElement&&document.documentElement.scrollHeight)
                        {
                            h1=document.documentElement.scrollHeight;
                        }
                        if(document.body) h2=document.body.scrollHeight;

                        var h=Math.max(h1, h2);
                        if(document.all) {h += 4;}
                        if(window.opera) {h += 1;}
                        a[i].style.height = a[i].parentNode.style.height = h +"px";
                    }
                }
            }
        }
        catch (ex){}
    } 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息