Ext.onReady(function()
{
Ext.QuickTips.init();
var loginForm=new Ext.FormPanel
({
standardSubmit: true,
url:'test.jsp',
renderTo:document.body,
frame:true,
title:'用户登陆',
width:400,
items:[
{
xtype:'textfield',
fieldLabel:' 用户名 ',
name:'uname',
width:180,
allowBlank:false,
blankText:'用户名不能为空',
minLength:6,
minLengthText:'用户名的长度为[6-20]',
maxLength:20,
maxLengthText:'用户名的长度为[6-20]'
},
{
xtype: 'textfield',
inputType:'password',
fieldLabel:'密 码',
name:'pwd',
width:180,
allowBlank:false,
blankText:'密码不能为空',
minLength:6,
minLengthText:'密码的长度为[6-20]',
maxLength:20,
maxLengthText:'密码的长度为[6-20]'
},
{
xtype: 'textfield',
fieldLabel:'验证码',
name:'val',
width:80,
allowBlank:false,
blankText:'验证码不能为空'
}
],
buttons: [
{
text: '登录',
type:'button',
handler:function()
{
if (!loginForm.getForm().isValid()) return;
loginForm.getForm().submit();
}
}
]
});
}
);
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
<title>Untitled Document</title>
<script>
// 求两个时间的天数差 日期格式为 YYYY-MM-dd
function daysBetween(DateOne,DateTwo)
{
var OneMonth = DateOne.substring(5,DateOne.lastIndexOf ('-'));
var OneDay = DateOne.substring(DateOne.length,DateOne.lastIndexOf ('-')+1);
var OneYear = DateOne.substring(0,DateOne.indexOf ('-'));
var TwoMonth = DateTwo.substring(5,DateTwo.lastIndexOf ('-'));
var TwoDay = DateTwo.substring(DateTwo.length,DateTwo.lastIndexOf ('-')+1);
var TwoYear = DateTwo.substring(0,DateTwo.indexOf ('-'));
var cha=((Date.parse(OneMonth+'/'+OneDay+'/'+OneYear)- Date.parse(TwoMonth+'/'+TwoDay+'/'+TwoYear))/86400000);
return Math.abs(cha);
}
////日期计算(加几天)。本方法相当于重载(第一个参数是‘n、s、h、d、q……’,第二个参数是要加的长度)
Date.prototype.DateAdd = function(strInterval, Number) {
var dtTmp = this;
switch (strInterval) {
case 's' :return new Date(Date.parse(dtTmp) + (1000 * Number));
case 'n' :return new Date(Date.parse(dtTmp) + (60000 * Number));
case 'h' :return new Date(Date.parse(dtTmp) + (3600000 * Number));
case 'd' :return new Date(Date.parse(dtTmp) + (86400000 * Number));
case 'w' :return new Date(Date.parse(dtTmp) + ((86400000 * 7) * Number));
case 'q' :return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number*3, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
case 'm' :return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
case 'y' :return new Date((dtTmp.getFullYear() + Number), dtTmp.getMonth(), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
}
}
////////////////////////格式化日期
Date.prototype.Format = function(formatStr)
{
var str = formatStr;
alert(str)
var Week = ['日','一','二','三','四','五','六'];
str=str.replace(/yyyy|YYYY/,this.getFullYear());
str=str.replace(/yy|YY/,(this.getYear() % 100)>9?(this.getYear() % 100).toString():'0' + (this.getYear() % 100));
str=str.replace(/MM/,this.getMonth()>9?this.getMonth().toString():'0' + this.getMonth());
str=str.replace(/M/g,this.getMonth());
str=str.replace(/w|W/g,Week[this.getDay()]);
str=str.replace(/dd|DD/,this.getDate()>9?this.getDate().toString():'0' + this.getDate());
str=str.replace(/d|D/g,this.getDate());
str=str.replace(/hh|HH/,this.getHours()>9?this.getHours().toString():'0' + this.getHours());
str=str.replace(/h|H/g,this.getHours());
str=str.replace(/mm/,this.getMinutes()>9?this.getMinutes().toString():'0' + this.getMinutes());
str=str.replace(/m/g,this.getMinutes());
str=str.replace(/ss|SS/,this.getSeconds()>9?this.getSeconds().toString():'0' + this.getSeconds());
str=str.replace(/s|S/g,this.getSeconds());
return str;
}
//String类型转换成Date类型
function StringToDate(DateStr)
{
var converted = Date.parse(DateStr);
var myDate = new Date(converted);
if (isNaN(myDate))
{
//var delimCahar = DateStr.indexOf('/')!=-1?'/':'-';
var arys= DateStr.split('-');
myDate = new Date(arys[0],--arys[1],arys[2]);
}
return myDate;
}
//由时间段('2009-03-10','2009-03-16')得到周六和周天的天数(----------------主函数---------------)
function test(startDate,endDate){
var myDate=StringToDate(startDate);//转换StringToDate
var num=daysBetween(startDate,endDate);//计算有几天(时间段的长度)
var Saturday=0;
var Sunday=0;
for(var i=0;i<num;i++){
var weekNum=(myDate.DateAdd('d',i)).Format('w');//遍历时间段判断每一天是周几
if(weekNum=='六')Saturday+=1;
if(weekNum=='日') Sunday+=1;
}
alert("周六有:"+Saturday);
alert("周天有:"+Sunday);
}
</script>
</head>
<body>
<input type="button" value=Test onclick="test('2009-03-10','2009-07-16')"><br>
</body>
</html>
|