欢迎光临
我们一直在努力

1. 一个类似于Calendar日期控件,不用再刷新页面。-.NET教程,Asp.Net开发

建站超值云服务器,限时71元/月

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

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 1. 一个类似于Calendar日期控件,不用再刷新页面。-.NET教程,Asp.Net开发
分享到: 更多 (0)