一个类似于Calendar日期控件,不用再刷新页面。
2008-05-01 04:07
357 查看
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
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
相关文章推荐
- 利用页面传值获取Calendar控件日期【转】
- 利用页面传值获取Calendar控件日期
- watir解决如web页面使用梅花雨calendar日期控件对只读控件的设值问题
- ASP.net下的前台日历控件源代码(不刷新页面)Calendar .js
- 对委托的理解winform usercontrol页面控件的刷新
- 再推荐一个好用的日期控件
- Ajax请求返回一个页面,实现页面局部刷新
- CalendarExtender控件日期格式 显示中文
- 一个无刷新效果定时自动更新页面的例子(ASP.NET2.0-应用xmlhttp)
- 一个可以进页面自动显示刷新效果的SwipeRefreshLayout
- ASP.NET子页面改变父页面控件的值(子页面刷新父页面)
- 页面自动刷新,不用按回车键来提交数据!
- 用javasript把一个页面的值传给另一个页面的控件
- 转一个日期输入控件,支持FF
- 在一个页面中用脚本实现对另一个页面的刷新
- ajax 笔记-- 写了一个不用刷新就能实现--用户名验证的例子
- 构建一个pool来管理无刷新页面的xmlhttp对象
- 日期控件Calendar的简单使用
- 构建一个pool来管理无刷新页面的xmlhttp对象
- C# .NET 遍历一个Web页面中所有的TextBox控件 并设置读写属性