ASP 精华源码收集(五年总结)第10/20页
更新时间:2008年10月20日 22:58:16 作者:
在5年的开发中,总结出来的一些源码
JS判断输入日期的正确性(有两个函数,很类似)
---------------------------
JS判断输入日期的正确性
<script language=javascript>
function strDateTime(str){
var reg = /^(\d{1,4})(-\/)(\d{1,2})\2(\d{1,2})$/;
var r = str.match(reg);
if(r==null)return false;
var d= new Date(r[1], r[3]-1,r[4]);
var newStr=d.getFullYear()+r[2]+(d.getMonth()+1)+r[2]+d.getDate()
return newStr==str
}
alert(strDateTime("2002-1-31"))
alert(strDateTime("2002-1-41"))
</script>
<script language=javascript>
function strDateTime(str){
var reg = /^(\d{1,4})(-\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;
var r = str.match(reg);
if(r==null)return false;
var d= new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]);
var newStr=d.getFullYear()+r[2]+(d.getMonth()+1)+r[2]+d.getDate()+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds()
return newStr==str
}
alert(strDateTime("2002-1-31 12:34:56"))
alert(strDateTime("2001-2-29 12:54:56"))
alert(strDateTime("2002-1-41 12:00:00"))
</script>
<script language="javascript">
var s="2002-4-16"
alert(chkDate(s));
function chkDate(sDate){
var r=/\d{4}(?:-\d{1,2}){0,2}/
//正则表达式,判断是否为yyyy-mm-dd,yyyy-mm,yyyy格式
if(sDate.match(r)==sDate){
var arr=sDate.split("-")
switch(arr.length){
//根据不同的yyyy-mm-dd,yyyy-mm格式判断年月日数字是否正确
case 3:
var tmpDate=new Date(arr[0],arr[1],arr[2]);
if(tmpDate.getMonth()==arr[1] && tmpDate.getFullYear()==arr[0]) return true;
break;
case 2:
if(arr[1]<13) return true;
break;
default:
return false;
}
}
return false;
}
</script>
/*
时间有效性判断函数
All by happywinds
*/
function verifyDate(textObj) {
var str=textObj.value;
textObj.value = textObj.value.replace(/\s+/g,"");
if(str.search(/^\d{4}-\d{1,2}-\d{1,2}$/) == 0){
var y = parseInt(str.split("-")[0]);
var m = parseInt(str.split("-")[1]);
var d = parseInt(str.split("-")[2]);
switch(m){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if(d>31){
return false;
textObj.focus();
textObj.select();
}else{
return true;
}
break;
case 2:
if((y%4==0 && d>29) ((y%4!=0 && d>28))){
return false;
textObj.focus();
textObj.select();
}else{
return true;
}
break;
case 4:
case 6:
case 9:
case 11:
if(d>30){
return false;
textObj.focus();
textObj.select();
}else{
return true;
}
break;
default:
return false;
textObj.focus();
textObj.select();
}
}else{
return false;
textObj.focus();
textObj.select();
}
}
meizz(梅花雨)斑竹的Javascript脚本日历输入控件(呵呵,我借花献佛了)
----------------------------------------------
调用的代码:
<script language=javascript src=../../setday.js></script>
<input onfocus="setday(this)">
或者
<script language=javascript src=../../setday.js></script>
<input name=txt><input type=button value=setday onclick="setday(this,document.all.txt)">
控件的代码:
<!--
//-------------------------------------------------------------------------------
// 这是我做的一个日历 Javascript 页面脚本控件,适用于微软的 IE (5.0以上)浏览器
// 主调用函数是 setday(this,[object]),[object]是控件输出的控件名,举两个具体调用的例子:
// 一、<input name=txt><input type=button value=setday onclick="setday(this,document.all.txt)">
// 二、<input onfocus="setday(this)">
// 若有什么不足的地方,或者您有更好的建议,请与我联系:mail: meizz@hzcnc.com
// 本日历的年份限制是(1000 - 9999)
//==================================================== WEB 页面显示部分 =====================================================
document.writeln('<div id=meizzDateLayer style="position: absolute; width: 142; height: 166; z-index: 9998; display: none">');
document.writeln('<span id=tmpSelectYearLayer style="z-index: 9999;position: absolute;top: 2; left: 18;display: none"></span>');
document.writeln('<span id=tmpSelectMonthLayer style="z-index: 9999;position: absolute;top: 2; left: 75;display: none"></span>');
document.writeln('<table border=0 cellspacing=1 cellpadding=0 width=142 height=160 bgcolor=#808080 onselectstart="return false">');
document.writeln(' <tr><td width=142 height=23 bgcolor=#FFFFFF><table border=0 cellspacing=1 cellpadding=0 width=140 height=23>');
document.writeln(' <tr align=center><td width=20 align=center bgcolor=#808080 style="font-size:12px;cursor: hand;color: #FFD700" ');
document.writeln(' onclick="meizzPrevM()" title="向前翻 月" Author=meizz><b Author=meizz><<</b>');
document.writeln(' </td><td width=100 align=center style="font-size:12px;cursor:default" Author=meizz>');
document.writeln(' <span Author=meizz id=meizzYearHead onclick="tmpSelectYearInnerHTML(this.innerText)"></span> 年 <span');
document.writeln(' id=meizzMonthHead Author=meizz onclick="tmpSelectMonthInnerHTML(this.innerText)"></span> 月</td>');
document.writeln(' <td width=20 bgcolor=#808080 align=center style="font-size:12px;cursor: hand;color: #FFD700" ');
document.writeln(' onclick="meizzNextM()" title="往后翻 月" Author=meizz><b Author=meizz>>></b></td></tr>');
document.writeln(' </table></td></tr>');
document.writeln(' <tr><td width=142 height=18 bgcolor=#808080>');
document.writeln('<table border=0 cellspacing=0 cellpadding=0 width=140 height=1 style="cursor:default">');
document.writeln('<tr align=center><td style="font-size:12px;color:#FFFFFF" Author=meizz>日</td>');
document.writeln('<td style="font-size:12px;color:#FFFFFF" Author=meizz>一</td><td style="font-size:12px;color:#FFFFFF" Author=meizz>二</td>');
document.writeln('<td style="font-size:12px;color:#FFFFFF" Author=meizz>三</td><td style="font-size:12px;color:#FFFFFF" Author=meizz>四</td>');
document.writeln('<td style="font-size:12px;color:#FFFFFF" Author=meizz>五</td><td style="font-size:12px;color:#FFFFFF" Author=meizz>六</td></tr>');
document.writeln('</table></td></tr><!-- Author:F.R.Huang(meizz) http://www.meizz.com/ mail: meizz@hzcnc.com 2002-10-8 -->');
document.writeln(' <tr><td width=142 height=120>');
document.writeln(' <table border=0 cellspacing=1 cellpadding=0 width=140 height=120 bgcolor=#FFFFFF>');
var n=0; for (j=0;j<5;j++){ document.writeln (' <tr align=center>'); for (i=0;i<7;i++){
document.writeln('<td width=20 height=20 id=meizzDay'+n+' style="font-size:12px" Author=meizz onclick=meizzDayClick(this.innerText)></td>');n++;}
document.writeln('</tr>');}
document.writeln(' <tr align=center><td width=20 height=20 style="font-size:12px" id=meizzDay35 Author=meizz ');
document.writeln(' onclick=meizzDayClick(this.innerText)></td>');
document.writeln(' <td width=20 height=20 style="font-size:12px" id=meizzDay36 Author=meizz onclick=meizzDayClick(this.innerText)></td>');
document.writeln(' <td colspan=5 align=right Author=meizz><span onclick=closeLayer() style="font-size:12px;cursor: hand"');
document.writeln(' Author=meizz title="作者: F.R.Huang(meizz) MAIL: meizz@hzcnc.com"><u>关闭本控件</u></span> </td></tr>');
document.writeln(' </table></td></tr><tr><td>');
document.writeln(' <table border=0 cellspacing=1 cellpadding=0 width=100% bgcolor=#FFFFFF>');
document.writeln(' <tr><td Author=meizz align=left><input Author=meizz type=button value="< " title="向前翻 年" onclick="meizzPrevY()" ');
document.writeln(' onfocus="this.blur()" style="font-size: 12px; height: 20px"><input Author=meizz title="向前翻 月" type=button ');
document.writeln(' value="<<" onclick="meizzPrevM()" onfocus="this.blur()" style="font-size: 12px; height: 20px"></td><td ');
document.writeln(' Author=meizz align=center><input Author=meizz type=button value=Today onclick="meizzToday()" ');
document.writeln(' onfocus="this.blur()" title="现在的年月" style="font-size: 12px; height: 20px"></td><td ');
document.writeln(' Author=meizz align=right><input Author=meizz type=button value=">>" onclick="meizzNextM()" ');
document.writeln(' onfocus="this.blur()" title="往后翻 月" style="font-size: 12px; height: 20px"><input ');
document.writeln(' Author=meizz type=button value=" >" title="往后翻 年" onclick="meizzNextY()"');
document.writeln(' onfocus="this.blur()" style="font-size: 12px; height: 20px"></td>');
document.writeln('</tr></table></td></tr></table></div>');
meizz(梅花雨)斑竹的Javascript脚本日历输入控件(二)
-------------------------------------------------------
//==================================================== WEB 页面显示部分 ======================================================
var outObject;
function setday(tt,obj) //主调函数
{
if (arguments.length > 2){alert("对不起!传入本控件的参数太多!");return;}
if (arguments.length == 0){alert("对不起!您没有传回本控件任何参数!");return;}
var dads = document.all.meizzDateLayer.style;var th = tt;
var ttop = tt.offsetTop; //TT控件的定位点高
var thei = tt.clientHeight; //TT控件本身的高
var tleft = tt.offsetLeft; //TT控件的定位点宽
var ttyp = tt.type; //TT控件的类型
while (tt = tt.offsetParent){ttop+=tt.offsetTop; tleft+=tt.offsetLeft;}
dads.top = (ttyp=="image")? ttop+thei : ttop+thei+6;
dads.left = tleft;
outObject = (arguments.length == 1) ? th : obj;
dads.display = '';
event.returnValue=false;
}
var MonHead = new Array(12); //定义阳历中每个月的最大天数
MonHead[0] = 31; MonHead[1] = 28; MonHead[2] = 31; MonHead[3] = 30; MonHead[4] = 31; MonHead[5] = 30;
MonHead[6] = 31; MonHead[7] = 31; MonHead[8] = 30; MonHead[9] = 31; MonHead[10] = 30; MonHead[11] = 31;
var meizzTheYear=new Date().getFullYear(); //定义年的变量的初始值
var meizzTheMonth=new Date().getMonth()+1; //定义月的变量的初始值
var meizzWDay=new Array(37); //定义写日期的数组
function document.onclick() //任意点击时关闭该控件
{
with(window.event.srcElement)
{ if (tagName != "INPUT" && getAttribute("Author")==null)
document.all.meizzDateLayer.style.display="none";
}
}
function meizzWriteHead(yy,mm) //往 head 中写入当前的年与月
{ document.all.meizzYearHead.innerText = yy;
document.all.meizzMonthHead.innerText = mm;
}
function tmpSelectYearInnerHTML(strYear) //年份的下拉框
{
if (strYear.match(/\D/)!=null){alert("年份输入参数不是数字!");return;}
var m = (strYear) ? strYear : new Date().getFullYear();
if (m < 1000 m > 9999) {alert("年份值不在 1000 到 9999 之间!");return;}
var n = m - 10;
if (n < 1000) n = 1000;
if (n + 26 > 9999) n = 9974;
var s = "<select Author=meizz name=tmpSelectYear style='font-size: 12px' "
s += "onblur='document.all.tmpSelectYearLayer.style.display=\"none\"' "
s += "onchange='document.all.tmpSelectYearLayer.style.display=\"none\";"
s += "meizzTheYear = this.value; meizzSetDay(meizzTheYear,meizzTheMonth)'>\r\n";
var selectInnerHTML = s;
for (var i = n; i < n + 26; i++)
{
if (i == m)
{selectInnerHTML += "<option value='" + i + "' selected>" + i + "年" + "</option>\r\n";}
else {selectInnerHTML += "<option value='" + i + "'>" + i + "年" + "</option>\r\n";}
}
selectInnerHTML += "</select>";
document.all.tmpSelectYearLayer.style.display="";
document.all.tmpSelectYearLayer.innerHTML = selectInnerHTML;
document.all.tmpSelectYear.focus();
}
function tmpSelectMonthInnerHTML(strMonth) //月份的下拉框
{
if (strMonth.match(/\D/)!=null){alert("月份输入参数不是数字!");return;}
var m = (strMonth) ? strMonth : new Date().getMonth() + 1;
var s = "<select Author=meizz name=tmpSelectMonth style='font-size: 12px' "
s += "onblur='document.all.tmpSelectMonthLayer.style.display=\"none\"' "
s += "onchange='document.all.tmpSelectMonthLayer.style.display=\"none\";"
s += "meizzTheMonth = this.value; meizzSetDay(meizzTheYear,meizzTheMonth)'>\r\n";
var selectInnerHTML = s;
for (var i = 1; i < 13; i++)
{
if (i == m)
{selectInnerHTML += "<option value='"+i+"' selected>"+i+"月"+"</option>\r\n";}
else {selectInnerHTML += "<option value='"+i+"'>"+i+"月"+"</option>\r\n";}
}
selectInnerHTML += "</select>";
document.all.tmpSelectMonthLayer.style.display="";
document.all.tmpSelectMonthLayer.innerHTML = selectInnerHTML;
document.all.tmpSelectMonth.focus();
}
function closeLayer() //这个层的关闭
{
document.all.meizzDateLayer.style.display="none";
}
function document.onkeydown()
{
if (window.event.keyCode==27)document.all.meizzDateLayer.style.display="none";
}
function IsPinYear(year) //判断是否闰平年
{
if (0==year%4&&((year%100!=0)(year%400==0))) return true;else return false;
}
function GetMonthCount(year,month) //闰年二月为29天
{
var c=MonHead[month-1];if((month==2)&&IsPinYear(year)) c++;return c;
}
function GetDOW(day,month,year) //求某天的星期几
{
var dt=new Date(year,month-1,day).getDay()/7; return dt;
}
function meizzPrevY() //往前翻 Year
{
if(meizzTheYear > 999 && meizzTheYear <10000){meizzTheYear--;}
else{alert("年份超出范围(1000-9999)!");}
meizzSetDay(meizzTheYear,meizzTheMonth);
}
function meizzNextY() //往后翻 Year
{
if(meizzTheYear > 999 && meizzTheYear <10000){meizzTheYear++;}
else{alert("年份超出范围(1000-9999)!");}
meizzSetDay(meizzTheYear,meizzTheMonth);
}
function meizzToday() //Today Button
{
meizzTheYear = new Date().getFullYear();
meizzTheMonth = new Date().getMonth()+1;
meizzSetDay(meizzTheYear,meizzTheMonth);
}
function meizzPrevM() //往前翻月份
{
if(meizzTheMonth>1){meizzTheMonth--}else{meizzTheYear--;meizzTheMonth=12;}
meizzSetDay(meizzTheYear,meizzTheMonth);
}
function meizzNextM() //往后翻月份
{
if(meizzTheMonth==12){meizzTheYear++;meizzTheMonth=1}else{meizzTheMonth++}
meizzSetDay(meizzTheYear,meizzTheMonth);
}
function meizzSetDay(yy,mm) //主要的写程序**********
{
meizzWriteHead(yy,mm);
for (var i = 0; i < 37; i++){meizzWDay[i]=""}; //将显示框的内容全部清空
var day1 = 1,firstday = new Date(yy,mm-1,1).getDay(); //某月第一天的星期几
for (var i = firstday; day1 < GetMonthCount(yy,mm)+1; i++){meizzWDay[i]=day1;day1++;}
for (var i = 0; i < 37; i++)
{ var da = eval("document.all.meizzDay"+i) //书写新的一个月的日期星期排列
if (meizzWDay[i]!="")
{ da.innerHTML = "<b>" + meizzWDay[i] + "</b>";
da.style.backgroundColor = (yy == new Date().getFullYear() &&
mm == new Date().getMonth()+1 && meizzWDay[i] == new Date().getDate()) ? "#FFD700" : "#ADD8E6";
da.style.cursor="hand"
}
else{da.innerHTML="";da.style.backgroundColor="";da.style.cursor="default"}
}
}
function meizzDayClick(n) //点击显示框选取日期,主输入函数*************
{
var yy = meizzTheYear;
var mm = meizzTheMonth;
if (mm < 10){mm = "0" + mm;}
if (outObject)
{
if (!n) {outObject.value=""; return;}
if ( n < 10){n = "0" + n;}
outObject.value= yy + "" + mm + "" + n ; //注:在这里你可以输出改成你想要的格式
closeLayer();
}
else {closeLayer(); alert("您所要输出的控件对象并不存在!");}
}
meizzSetDay(meizzTheYear,meizzTheMonth);
// -->
web进度条
----------------------------------
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<SCRIPT LANGUAGE=javascript>
<!--
var myTime=0
function counter(){
myTime++
per.innerHTML="<font size=2 color=darkblue> "+myTime+"%</font>"
if (myTime<100)
setTimeout("counter()",40);
else{
window.open("http://www.sina.com.cn",null,"fullscreen=yes,channelmode=no,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no")
}
}
function window_onload() {
counter()
}
//-->
</SCRIPT>
</HEAD>
<BODY LANGUAGE=javascript onload="return window_onload()">
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<table border="0" cellpadding="0" cellspacing="0" width="50%" align=center>
<tr>
<td width="51%" noWrap>
<p align="right"><FONT face=宋体 color=navy
size=2>正在加载:</FONT></p> </td>
<td width="4%" bordercolor="#000000">
<marquee align="middle" direction="right" scrolldelay="1" bgcolor="gainsboro" scrollamount="2" style="BORDER-RIGHT: black 1px outset; BORDER-TOP: black 1px outset; FONT-SIZE: xx-small; BORDER-LEFT: black 1px outset; WIDTH: 133px; COLOR: #000080; BORDER-BOTTOM: black 1px outset; HEIGHT: 13px"
behavior="slide"
>███████████████████████████████████████████████████████████████████████████████</marquee>
</td><td width="45%" align=left><div id=per></div></td>
</tr>
</table>
</BODY>
</HTML>
asp导入word和excel
注意:两个函数中的“data“是网页中要导出的table的 id
<input type="hidden" name="out_word" onclick="vbscript:buildDoc" value="导出到word" class="notPrint">
<input type="hidden" name="out_excel" onclick="AutomateExcel();" value="导出到excel" class="notPrint">
导出到Excel代码
<SCRIPT LANGUAGE="JavaScript">
<!--
function AutomateExcel()
{
// Start Excel and get Application object.
var oXL = new ActiveXObject("Excel.Application");
// Get a new workbook.
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
var table = document.all.data;
var hang = table.rows.length;
var lie = table.rows(0).cells.length;
// Add table headers going cell by cell.
for (i=0;i<hang;i++)
{
for (j=0;j<lie;j++)
{
oSheet.Cells(i+1,j+1).Value = table.rows(i).cells(j).innerText;
}
}
oXL.Visible = true;
oXL.UserControl = true;
}
//-->
</SCRIPT>
导出到Word代码
<script language="vbscript">
Sub buildDoc
set table = document.all.data
row = table.rows.length
column = table.rows(1).cells.length
Set objWordDoc = CreateObject("Word.Document")
'objWordDoc.Application.Documents.Add theTemplate, False
objWordDoc.Application.Visible=True
Dim theArray(20,10000)
for i=0 to row-1
for j=0 to column-1
theArray(j+1,i+1) = table.rows(i).cells(j).innerTEXT
next
next
objWordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore("综合查询结果集") //显示表格标题
objWordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore("")
Set rngPara = objWordDoc.Application.ActiveDocument.Paragraphs(1).Range
With rngPara
.Bold = True //将标题设为粗体
.ParagraphFormat.Alignment = 1 //将标题居中
.Font.Name = "隶书" //设定标题字体
.Font.Size = 18 //设定标题字体大小
End With
Set rngCurrent = objWordDoc.Application.ActiveDocument.Paragraphs(3).Range
Set tabCurrent = ObjWordDoc.Application.ActiveDocument.Tables.Add(rngCurrent,row,column)
for i = 1 to column
objWordDoc.Application.ActiveDocument.Tables(1).Rows(1).Cells(i).Range.InsertAfter theArray(i,1)
objWordDoc.Application.ActiveDocument.Tables(1).Rows(1).Cells(i).Range.ParagraphFormat.alignment=1
next
For i =1 to column
For j = 2 to row
objWordDoc.Application.ActiveDocument.Tables(1).Rows(j).Cells(i).Range.InsertAfter theArray(i,j)
objWordDoc.Application.ActiveDocument.Tables(1).Rows(j).Cells(i).Range.ParagraphFormat.alignment=1
Next
Next
End Sub
</SCRIPT>
相关文章
asp连接SQL和Access数据代码(asp里的随机函数)
asp连接SQL和Access数据代码,asp里的随机函数,需要的朋友可以参考下2012-09-09
最新评论