下面是个简单例子,月末可能得多加判断:<script language="javascript" type="text/javascript">function c(obj)
{
if (isNaN(obj.value))
{
return false;
}
var no = parseInt(obj.value);
var d = new Date();
obj.value = d.getYear()+'-'+d.getMonth()+'-'+(d.getDate()+no);
}</script>
</HEAD><BODY>
<INPUT TYPE="text" NAME="" onkeyup="c(this);return true;">
</BODY>
</HTML>
{
if (isNaN(obj.value))
{
return false;
}
var no = parseInt(obj.value);
var d = new Date();
obj.value = d.getYear()+'-'+d.getMonth()+'-'+(d.getDate()+no);
}</script>
</HEAD><BODY>
<INPUT TYPE="text" NAME="" onkeyup="c(this);return true;">
</BODY>
</HTML>
<script language="JavaScript">
<!--
function getDate(){
if(event.keyCode != 13) return;
var d = parseInt(this.value,10);
if(isNaN(d)){ alert("输入非法!"); return;}
var date = new Date();
date.setDate(date.getDate() + d);
this.value = date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
}
document.getElementById("txtDate").onkeypress=getDate;
//-->
</script>
<script language="javascript" type="text/javascript">function c(obj)
{
if (isNaN(obj.value) || event.keyCode == 8)
{
return false;
}
var no = parseInt(obj.value);
var d = new Date();
obj.value = d.getYear()+'-'+(d.getMonth()+1)+'-'+(d.getDate()+no);
}</script>
</HEAD><BODY>
<INPUT TYPE="text" NAME="" onkeyup="c(this);return true;">
</BODY>
</HTML>