1. 一个类似于Calendar日期控件,不用再刷新页面。
2. 判断文本控件里的值是否能转换成日期型。
.htc 例1:
/*
*xpMask.htc
*
*/
//------------------------------------------------------------------------------------------------------
<PUBLIC:COMPONENT
lightWeight=false
>
<PUBLIC:DEFAULTS
contentEditable=false
tabStop=true
/>
<PUBLIC:attach event="ondocumentready" onevent="initCoolMask()" />
<PUBLIC:attach event="ondetach" onevent="cleanupCoolMask()" />
<PUBLIC:property name="maskType" value="" />
<PUBLIC:property name="realValue" value="" />
<PUBLIC:property name="toolTipStr" value="" />
<script language="VBScript">
sub initCoolMask()
attachEvent "onreadystatechange", GetRef("coolMaskInputBlur")
attachEvent "onfocus", GetRef("coolMaskInputFocus")
attachEvent "onblur", GetRef("coolMaskInputBlur")
coolMaskInputBlur
end sub
sub cleanupCoolMask()
detachEvent "onreadystatechange", GetRef("coolMaskInputBlur")
detachEvent "onfocus", GetRef("coolMaskInputFocus")
detachEvent "onblur", GetRef("coolMaskInputBlur")
end sub
sub coolMaskInputFocus()
with element
if not .realValue = "" then .value = .realValue
.select()
end with
end sub
sub coolMaskInputBlur()
with element
select case ucase(.maskType)
case "DATETIME"
.realValue = .value
.value = maskDatetime(.value)
.toolTipStr = .ToolTip
case "SHORTDATE"
.realValue = .value
if maskDate(.value, "short") = formatDateTime("1900-1-1 0:00:00", vbShortDate) then
.value = ""
.toolTipStr = "Format: yyyy-mm-dd "
else
.value = maskDate(.value, "short")
if not .realValue = "" then
.toolTipStr = "Format: "&.realValue
else
.toolTipStr = "Format: yyyy-mm-dd "
end if
end if
.title =.toolTipStr
case "MEDIUMDATE"
.realValue = .value
.value = maskDate(.value, "medium")
case "LONGDATE"
.realValue = .value
.value = maskDate(.value, "long")
case "ZIPCODE"
.realValue = parseChar(.value, array(" ", "-"))
.value = maskZip(.value)
case "PHONE"
.realValue = parseChar(.value, array(" ", "(", ")", "-", "."))
.value = maskPhone(.value)
case "PERCENT"
.realValue = parseChar(.value, array(" ", "%"))
.value = maskPercent(.value)
case else
.realValue = .value
end select
end with
end sub
function parseChar(sStr, sChar)
dim i, zChar, sNewStr
if typeName(sChar) = "string" then zChar = Array(sChar) else zChar = sChar
sNewStr = sStr
for i = lBound(zChar) to uBound(zChar)
sNewStr = replace(sNewStr, cstr(zChar(i)), "")
next
parseChar = sNewStr
end function
function setViewState(bState)
with element
if not bState then
.runtimeStyle.color = .style.color
else
.runtimeStyle.color = "red"
end if
end with
end function
function maskDate(sValue, sType)
if IsNumeric(sValue) then
@#sValue = parseChar(sValue, array(" ", "-", "/", ",", ".", "\", "^", "&", "*", "@", "~", "`", "@#", "!", "#", "$", "%", "|", "(", ")", "+", "_", "=", ";", "?", ":", "{", "}", "[", "]", "<", ">"))
if len(sValue) = 8 then sValue = left(sValue, 4) & "-" & left(right(sValue, 4), 2) & "-" & right(right(sValue, 4), 2)
if len(sValue) = 6 then sValue = left(sValue, 4) & "-0" & left(right(sValue, 2), 1) & "-0" & right(right(sValue, 2), 1)
end if
dim zMonth
zMonth = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
if len(trim(sValue)) = 0 then
maskDate = ""
setViewState false
elseif not(isDate(sValue)) then
maskDate = "DATE ERROR"
setViewState true
else
select case (sType)
case "medium"
maskDate = day(dateValue(sValue)) & "-" & left(zMonth(month(dateValue(sValue)) - 1), 3) & "-" & year(dateValue(sValue))
case "long"
maskDate = zMonth(month(dateValue(sValue)) - 1) & " " & day(dateValue(sValue)) & ", " & year(dateValue(sValue))
case else
maskDate = formatDateTime(sValue, vbShortDate)
end select
setViewState false
end if
end function
function maskDatetime(sValue)
dim sNewValue
sNewValue = parseChar(sValue, array(" ", "-", "/", ",", ".", "\", "^", "&", "*", "@", "~", "`", "@#", "!", "#", "$", "%", "|", "(", ")", "+", "_", "=", ";", "?", ":", "{", "}", "[", "]", "<", ">"))
if len(sNewValue) = 0 then
maskDatetime = ""
setViewState false
elseif (len(sNewValue) <> 8 and len(sNewValue) <> 7 and len(sNewValue) <> 6) or not isnumeric(sNewValue) then
maskDatetime = "DATE ERROR"
setViewState true
else
if len(sNewValue) = 8 then sNewValue = left(sNewValue, 4) & "-" & left(right(sNewValue, 4), 2) & "-" & right(right(sNewValue, 4), 2)
if len(sNewValue) = 7 then
if IsNumeric(right(sValue, 2)) then
sNewValue = left(sNewValue, 4) & "-0" & left(right(sNewValue, 3), 1) & "-" & right(right(sNewValue, 3), 2)
else
sNewValue = left(sNewValue, 4) & "-" & left(right(sNewValue, 3), 2) & "-0" & right(right(sNewValue, 3), 1)
end if
end if
if len(sNewValue) = 6 then sNewValue = left(sNewValue, 4) & "-0" & left(right(sNewValue, 2), 1) & "-0" & right(right(sNewValue, 2), 1)
if not(isDate(sNewValue)) then
maskDatetime = "DATE ERROR"
setViewState true
else
@#sNewValue = parseChar(sNewValue, array(" ", "-", "/", ",", "."))
maskDatetime = FormatDateTime(sNewValue, 2)
setViewState false
end if
end if
end function
function maskZip(sValue)
dim sNewValue
sNewValue = parseChar(sValue, array(" ", "-"))
if len(sNewValue) = 0 then
maskZip = ""
setViewState false
elseif (len(sNewValue) <> 5 and len(sNewValue) <> 9) or not isnumeric(sNewValue) then
maskZip = "ZIPCODE ERROR"
setViewState true
else
if len(sNewValue) = 9 then sNewValue = left(sNewValue, 5) & "-" & right(sNewValue, 4)
maskZip = sNewValue
setViewState false
end if
end function
function maskPhone(sValue)
dim sNewValue
sNewValue = parseChar(sValue, array(" ", "(", ")", "-", "."))
if len(sNewValue) = 0 then
maskPhone = ""
setViewState false
elseif (len(sNewValue) <> 7 and len(sNewValue) <> 10) or not isnumeric(sNewValue) then
maskPhone = "PHONE ERROR"
setViewState true
else
select case len(sNewValue)
case 7
maskPhone = left(sNewValue, 3) & "-" & right(sNewValue, 4)
case 10
maskPhone = "(" & left(sNewValue, 3) & ") " & mid(sNewValue, 4, 3) & "-" & right(sNewValue, 4)
end select
setViewState false
end if
end function
function maskPercent(sValue)
dim sNewValue
sNewValue = parseChar(sValue, array(" ", "%"))
if len(sNewValue) = 0 then
maskPercent = ""
setViewState false
else
on error resume next
err.clear
maskPercent = formatPercent(sNewValue)
if err.number = 13 then
on error goto 0
maskPercent = "PERCENT ERROR"
setViewState true
exit function
end if
on error goto 0
setViewState false
end if
end function
</script>
</PUBLIC:COMPONENT>
//------------------------------------------------------------------------------------------------------
.css 例1:
/*
*xpText.css
*
*/
.coolMask
{
FONT-SIZE: 10pt;
BEHAVIOR: url(../Htc/coolMask.htc);
FONT-FAMILY: Verdana, Arial, Helvetica;
}
//------------------------------------------------------------------------------------------------------
页面调用:
<asp:textbox id="birthday" CssClass="coolMask" ondblclick="javascript: setday(this);" maskType="shortDate" runat="server" Width="106px"></asp:textbox>
注意:
CssClass="coolMask" 这个不用说了,大家都知道是什么
ondblclick="javascript: setday(this);" 这是双激事件
maskType="shortDate" maskType属性在coolWindowsCalendar.js中文定义了,
maskType属性类型一共有如下几种:
DATETIME :日期
SHORTDATE :日期
MEDIUMDATE :日期
LONGDATE :日期
PHONE :电话号码
PERCENT :百分数
realValue="" : realValue属性在coolWindowsCalendar.js中文定义了,
realValue : 用来保存当前值,( element.realValue = textbox.value)
toolTipStr : toolTipStr 属性在coolWindowsCalendar.js中文定义了,
toolTipStr : 用来显示格式, 就是title提示框,
查看地址:http://print.itgaga.org/PrintERP/OrderManage/Bus_Invoice_EFrame.aspx(填写日期)
源代码:data.rar
下一篇:一个完美的日期控件 + 一个用脚本断判日期型的方法(1) >>
相关文章:
- · ASP.NET分页组件更新版本
- · 一种快速存取选择条目的方案(Asp.Net+C#)
- · Asp.Net(C#)+Sql Server三层架构下数据存取方案(五)
- · Asp.Net(C#)+Sql Server三层架构下数据存取方案(四)
- · Asp.Net(C#)+Sql Server三层架构下数据存取方案(三)
- · Asp.Net(C#)+Sql Server三层架构下数据存取方案(二)
- · Asp.Net(C#)+Sql Server三层架构下数据存取方案(一)
- · 在asp.net中使用excel模板
- · 关于ASPNET在IIS一些问题的经验总结
- · 认识Whidbey
- · 小程序构成大项目之——分页显示
- · ASP.NET 数据库缓存依赖
- · Global.asax 和 HttpApplication 类
- · 办公自动化系统公文归档代码
- · Asp.net性能优化总结(一)
- · 如何在DataGrid里面产生滚动条而不滚动题头
- · Whidbey中客户端回调机制(三)
- · Whidbey中客户端回调机制(二)
- · Whidbey中客户端回调机制(一)
- · ASP.NET分页组件 0.1.0
- · INI文件的操作(ASP.NET+C#)
- · Asp.net+Xml开发网络硬盘
- · ASP.NET高级应用(3)
- · ASP.NET高级应用(2)
- · ASP.NET高级应用(1)
- · Net 是未来的趋势, 为什么?
- · 迁移到 ASP .NET:需考虑的重要问题
- · ASP+与VB.Net问答QA总汇
- · 基于.NET的Web应用框架构建模式
- · Observer模式深度探索
- · VSS控制存储过程,及其asp.net的远程调试
- · 简介使用ASP.NET访问Oracle数据库的方法
- · ASP.NET编程中的十大技巧
- · ASP.NET Whidbey中personalization和membership的一些特征
- · 使用更精简的代码保证 ASP.NET 应用程序的安全
- · ASP.NET Whidbey 中新的代码编译功能
- · ASP.NET的缓存技术
- · ASP.net 中的页面继承实现和通用页面的工厂模式的实现
