一个挺方便的挂历形式选择日期的js代码
2008-01-26 22:21
701 查看
<script language="javascript">
function showCalendar() {
var lastMouseX;
var lastMouseY;
var features;
var width,height;
width = 230;
height = 200;
if (navigator.appName.indexOf("Microsoft") != -1) e = window.event;
lastMouseX = e.screenX;
lastMouseY = e.screenY;
if (lastMouseX - width < 0) {
lastMouseX = width;
}
if (lastMouseY + height > screen.height) {
lastMouseY -= (lastMouseY + height + 50) - screen.height;
}
lastMouseX -= width;
lastMouseY += 10;
features = "width="+width+",height="+height+",status=no,resizable=no,"
features += "screenX=" + lastMouseX + ",left=" + lastMouseX + "screenY=" + lastMouseY + ",top=" + lastMouseY;
FileName = "inc/Calendar.asp?formElt=" + arguments[0];
vWinCal = window.open(FileName, "Calendar", features,false);
vWinCal.focus();
}
function isdate(strDate){
var re=/^/d{4}-/d{1,2}-/d{1,2}$/;
var r=strDate.match(re);
if (r==null) return false;
var strSeparator = "-"; //日期分隔符
var strDateArray;
var intYear;
var intMonth;
var intDay;
var boolLeapYear;
strDateArray = strDate.split(strSeparator);
if(strDateArray.length!=3) return false;
intYear = parseInt(strDateArray[0],10);
intMonth = parseInt(strDateArray[1],10);
intDay = parseInt(strDateArray[2],10);
if(isNaN(intYear)||isNaN(intMonth)||isNaN(intDay)) return false;
if(intMonth>12||intMonth<1) return false;
if((intMonth==1||intMonth==3||intMonth==5||intMonth==7||intMonth==8||intMonth==10||intMonth==12)&&(intDay>31||intDay<1)) return false;
if((intMonth==4||intMonth==6||intMonth==9||intMonth==11)&&(intDay>30||intDay<1)) return false;
if(intMonth==2){
if(intDay<1) return false;
boolLeapYear = false;
if((intYear%100)==0){
if((intYear%400)==0) boolLeapYear = true;
}
else{
if((intYear%4)==0) boolLeapYear = true;
}
if(boolLeapYear){
if(intDay>29) return false;
}
else{
if(intDay>28) return false;
}
}
return true;
}
function alertDate(input) {
strDate = input.value;
if (strDate == '') return;
if(!isdate(strDate)) {
alert("请输入正确地的日期格式[YYYY-MM-DD]。");
input.focus();
input.select();
}
}
</script>
<input type="text" name="todate" size="16" onblur="alertDate(this)">
<a href=#1 onclick="javascript:showCalendar('form1.todate');">
<img src="images/cal.gif" border=0 width="18" height="17"></a>
function showCalendar() {
var lastMouseX;
var lastMouseY;
var features;
var width,height;
width = 230;
height = 200;
if (navigator.appName.indexOf("Microsoft") != -1) e = window.event;
lastMouseX = e.screenX;
lastMouseY = e.screenY;
if (lastMouseX - width < 0) {
lastMouseX = width;
}
if (lastMouseY + height > screen.height) {
lastMouseY -= (lastMouseY + height + 50) - screen.height;
}
lastMouseX -= width;
lastMouseY += 10;
features = "width="+width+",height="+height+",status=no,resizable=no,"
features += "screenX=" + lastMouseX + ",left=" + lastMouseX + "screenY=" + lastMouseY + ",top=" + lastMouseY;
FileName = "inc/Calendar.asp?formElt=" + arguments[0];
vWinCal = window.open(FileName, "Calendar", features,false);
vWinCal.focus();
}
function isdate(strDate){
var re=/^/d{4}-/d{1,2}-/d{1,2}$/;
var r=strDate.match(re);
if (r==null) return false;
var strSeparator = "-"; //日期分隔符
var strDateArray;
var intYear;
var intMonth;
var intDay;
var boolLeapYear;
strDateArray = strDate.split(strSeparator);
if(strDateArray.length!=3) return false;
intYear = parseInt(strDateArray[0],10);
intMonth = parseInt(strDateArray[1],10);
intDay = parseInt(strDateArray[2],10);
if(isNaN(intYear)||isNaN(intMonth)||isNaN(intDay)) return false;
if(intMonth>12||intMonth<1) return false;
if((intMonth==1||intMonth==3||intMonth==5||intMonth==7||intMonth==8||intMonth==10||intMonth==12)&&(intDay>31||intDay<1)) return false;
if((intMonth==4||intMonth==6||intMonth==9||intMonth==11)&&(intDay>30||intDay<1)) return false;
if(intMonth==2){
if(intDay<1) return false;
boolLeapYear = false;
if((intYear%100)==0){
if((intYear%400)==0) boolLeapYear = true;
}
else{
if((intYear%4)==0) boolLeapYear = true;
}
if(boolLeapYear){
if(intDay>29) return false;
}
else{
if(intDay>28) return false;
}
}
return true;
}
function alertDate(input) {
strDate = input.value;
if (strDate == '') return;
if(!isdate(strDate)) {
alert("请输入正确地的日期格式[YYYY-MM-DD]。");
input.focus();
input.select();
}
}
</script>
<input type="text" name="todate" size="16" onblur="alertDate(this)">
<a href=#1 onclick="javascript:showCalendar('form1.todate');">
<img src="images/cal.gif" border=0 width="18" height="17"></a>
相关文章推荐
- 发布一个的Web日期选择控件及源码(其中的js代码来自于Microsoft CRM)
- 一个JS日期选择器比较不能小于开始时间的JS脚本
- 一个非常好的JS日期选择控件
- js实现点击文本框显示日期选择器特效代码分享
- js 跨域的问题 (同一个主域名不同的二级域名下的跨域问题) 解决 WdatePicker.js my97日期选择控件
- 非常实用的选择输入日期的特效,JS代码。
- Js 日期选择,可以的一个页面中重复使用本JS日历,兼容IE及火狐等主流浏览器,而且界面简洁、美观,操作体验也不错。
- 原创:js代码, 让dedecms支持Tag选择, 添加内容更为方便,不用手输Tag
- Js日期选择器并自动加入到输入框中示例代码
- js代码收藏三:My97DatePicker日期选择的限制
- JS写的一个日期选择器
- js calendar橙色日期选择器代码
- js实现编辑框用户名 密码 日期选择 按钮提交特效代码
- JS写的一个日期选择控件(移动网页的),写得不当的地方,望各位大神指正
- js代码收藏三:My97DatePicker日期选择的限制
- 题型:编写一段JS代码提取URL中的各个GET参数,并按Key_Value的形式返回到一个对象中(如:Json结构)
- 原生JS实现左右箭头选择日期实例代码
- js实现点击文本框显示日期选择器特效代码分享
- 一个速度超快的日期选择JS