文本字段中的填充日期
这个问题在这里已经有了答案:
Date.getMonth:
getMonth返回的值是一个介于0和11之间的整数。0对应于一月份,一月份到二月份,依此类推。
参考。
HTML元素:
<p>Today's Date<br />
<input id="date" type="text" name="curDate" size="50" /><br />
Pick-up Date<br />
<input type='text' name='duedateField' id='duedateField' value='' /></p>
使用这个javascript:
var month = Date.getMonth();
var date = Date.getDate();
var year = Date.getYear();
var deliverymonth;
var deliverydate;
var deliveryyear;
var message = month + "/" + date + "/" + year;
document.getElementById('date').innerHTML=message;
if(month == 11 && date >= 29){
deliveryyear = year + 1;
deliverymonth = 1;
deleverydate = date - 28;
}else{
switch(month)
{
case 0,2,4,6,7,9,11:
if(date >= 29){
deliverymonth = month + 1;
deliverydate = date - 28;
}else{
deliverydate = date + 3;
}
break;
case 3,5,8,10:
if(date >= 28){
deliverymonth = month + 1;
deliverydate = date - 27;
}else{
deliverydate = date + 3;
}
break;
case 1:
if(date >= 26){
deliverymonth = month + 1;
deliverydate = date - 25;
}else{
deliverydate = date + 3;
}
break;
default:
break;
}
var deliverymessage = deliverymonth + "/" + deliverydate + "/" + deliveryyear;
document.getElementById('duedateField').innerHTML=deliverymessage;
链接地址: http://www.djcxy.com/p/77517.html