1.日期大小比较 var regS = new RegExp("-","gi"); var bvalue=document.all("today").value.replace(regS,"/"); var evalue=document.all("providerConfirmValidity").value.replace(regS,"/"); var d1 = new Date(bvalue); var d2 = new Date(evalue); if(Date.parse(d1) - Date.parse(d2)>=0){ alert("有效确认时间必须大于当前时间 !"); document.all("providerConfirmValidity").focus(); return false; } 2.只能输入数字的文本框(非数字自动回退)。 <input type='text' name='netMatCount' size='8' οnkeyup="this.value=this.value.replace(/[^/d/.]/g,'')" onbeforepaste="clipboardData.setData ('text',clipboardData.getData('text').replace(/^(-|/+)?(/d+/./d+)$/,''))" /> var price = /^/d+(/./d{1,4})?$/; if(!price.test(form1.netMatCount.value)){ alert("请填写需求数量 !"); return false; } /** * 文本框只允许输入数字或小数点时调用此方法。 * obj:文本框对象 */ function clearNoNum(obj){ if(inNaN(obj.value)) { obj.value = obj.value.replace(/[^/d.]/g,""); //先把非数字的都替换掉,除了数字和. obj.value = obj.value.replace(/^/./g,"");//必须保证第一个为数字而不是. obj.value = obj.value.replace(//.{2,}/g,"."); //保证只有出现一个.而没有多个. //保证.只出现一次,而不能出现两次以上 obj.value = obj.value.replace(".","$#$").replace(//./g,"").replace("$#$","."); } } 3.一组复选框,至少必须有一项选中 function selectOne(checkboxName,describe){ for(var i=1;i<checkboxName.length;i++){ if(checkboxName[i].checked==true){ return true; } } alert("请选择" + describe + "!"); return false; } 4.验证一个在某个区间的正整数 function isAreaInt(myString,min,max){ if(!isInt(myString)){ return false; } if(parseInt(myString)>max||parseInt(myString)<min){ return false; } return true; } 5.打开一个窗口,使窗口出现在屏幕中心位置,有滚动条,窗口大小可变 function winOpen(fileName,winName,winWidth,winHeight){ var winName=window.open(fileName,winName,"top=" + (screen.height-winHeight)/2 + ",left=" + (screen.width-winWidth)/2 + ",width=" + winWidth + ",height=" + winHeight + ",scrollbars=yes,resizable=yes,location=no,toolbar=no,status=no"); winName.focus(); } 6.打开一个窗口,使窗口出现在屏幕中心位置,窗口大小固定,有滚动条 function winOpenSizeBar(fileName,winName,winWidth,winHeight){ var winName=window.open(fileName,winName,"top=" + (screen.height-winHeight)/2 + ",left=" + (screen.width-winWidth)/2 + ",width=" + winWidth + ",height=" + winHeight + ",scrollbars=yes,resizable=no,location=no,toolbar=no,status=no"); winName.focus(); } 7.高亮显示表格中的一行 function choose_color(tableId,row,newColor){ var bgColor = "#E1FFFF"; if (newColor&&newColor != "") { bgColor = newColor; } var obj = document.getElementById(tableId); var rowCount = obj.rows.length; for (var i=0;i< rowCount; i++){ obj.rows(i).style.backgroundColor = ""; } row.style.backgroundColor = bgColor; } <tr height="30" align="right" οnmοusemοve="choose_color('firstTable',this)"> 8.去掉字串两边的空格 function trim(str) { return lTrim(rTrim(str)); } 9.email的判断。 function ismail(mail) { return(new RegExp(/^/w+((-/w+)|(/./w+))*/@[A-Za-z0-9]+((/.|-)[A-Za-z0-9]+)*/.[A-Za-z0-9]+$/).test(mail)); } 10.高亮替换 window.onload = function() { for( var i = 0; i < document.getElementsByTagName("ol").length; i++ ) { nav(document.getElementsByTagName("ol")[i]); } function nav(obj) { for( var i = 0; i < obj.getElementsByTagName("li").length; i++ ) { obj.getElementsByTagName("li")[i].onmousemove = function() { this.style.background = "#f8f8f8"; this.style.border= "3px solid #e2762e"; } obj.getElementsByTagName("li")[i].onmouseout = function() { this.style.background = "#ffffff"; this.style.border= "1px solid #dbdbdb"; } } } } 11.Table隔行换色、移动换色 <mce:script language="javascript"><!-- function senfe(o,a,b,c,d){ var t=document.getElementById(o).getElementsByTagName("tr"); for(var i=0;i<t.length;i++){ t[i].style.backgroundColor=(t[i].sectionRowIndex%2==0)?a:b; t[i].οnclick=function(){ if(this.x!="1"){ this.x="1"; this.style.backgroundColor=d; }else{ this.x="0"; this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b; } } t[i].οnmοuseοver=function(){ if(this.x!="1")this.style.backgroundColor=c; } t[i].οnmοuseοut=function(){ if(this.x!="1")this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b; } } } // --></mce:script> <mce:script language="javascript"><!-- //senfe("表格名称","奇数行背景","偶数行背景","鼠标经过背景","点击后背景"); senfe("changecolor","#f3f8fd","#ffffff","#ADADAD","#f391a9"); // --></mce:script> 12.Span装载数据,超出部分用省略号替换,鼠标提示 <span name="dd" style="width:160px;height:15px;text-overflow:ellipsis;overflow:hidden;white-space:nowrap" οnmοuseοver="this.title=this.innerText"> 测试标准长度,超出部分用省略号替换。 </span>