日期:2013-11-07  浏览次数:20478 次

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(" &q