日期:2014-05-17  浏览次数:20704 次

输入框如何正确输入标准日期
我有一个输入框,要实现输入为日期格式,比如2007-3-1   ,按照   年-月-日 的格式排,当格式不正确自动回退,而不是那种弹出对话框的方式,有哪位朋友可以讲解下吗

------解决方案--------------------
实现方式:
1、在日期输入框边注明标准格式,并提示不按标准格式输入将会导致出错
2、正则表达式
------解决方案--------------------
functon checkdate(str)

checkdate=true

if len(str)> 10 or len(str) <8 then '判断总长度是否正确
checkdate=false
exit function
end if

if ubound(split(str), "- ")> 2 then '判断格式是否正确
checkdate=false
exit function
end if

if not isnumeric(split(str)(0)) or len(split(str)(0)) <> 4 then '判断年是否正确
checkdate=false
exit function
end if

' ' ' '月,日,是否正确

end function

方法笨,确很有效。
------解决方案--------------------

http://byt.0755zb.com/js/Mymodify.js
下载上面的js文件保存,然后在需要用到输入日期的页丰调用这个JS文件。

<script src= "date.js "> </script>
<input name= "odate " type= "text " class= "input1 " size= "15 " onFocus= "show_cele_date(odate, ' ', ' ',odate) " readonly />