Date1输入2009-08-10 Date2自动获取的值加30天
但是现在Date2获取的值全是很长一串数字,麻烦高手帮我看看,谢谢!<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<script language="javascript">
function zkch()
{
var DateObj = new Date();
var AddDayNumber = 30;
var Date1=document.myform.Date1.value;
Date2=DateObj.setDate(DateObj.getDate() + AddDayNumber);
document.myform.Date2.value=Date2;
}
</script>
<script language="javascript">
sub checknum(my)
if isnumeric(Date2.value)=false then
msgbox "请输入数字,OK!"
Date2.value=""
end if
end sub
</script>
 <form method="POST" action="xzsl.asp" name="myform"> 
    <TR>
      <TD height="30" colspan="14" align="left" valign="middle" ><FONT style="LINE-HEIGHT: 100%"><FONT face=Wingdings color=#99ccff >v</FONT></FONT><FONT color=#ff6600>签发时间:
          <input type="text" name="Date1" size="10" onKeyUp="zkch()" onBlur="checknum(this)" value="0">
      </FONT></TD>
    </TR>
  <TR>
      <TD height="30" colspan="14" align="left" valign="middle" ><FONT style="LINE-HEIGHT: 100%"><FONT face=Wingdings 
      color=#99ccff >v</FONT></FONT><FONT color=#ff6600>有效期:
          <input type="text" name="Date2"  size="10" readonly style="background-color: #edefef">
      </FONT></TD>
    </TR>
    </form>
</body>
</html>

解决方案 »

  1.   

    输入日期的话<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    </head> 
    <body> 
    <script language="javascript"> 
    function zkch() 

    var DateObj = new Date(); 
    var AddDayNumber = 30; 
    var Date1=document.myform.Date1.value;
    Date1 = Date1.replace(/-/g,"/");
    DateObj = new Date(Date1); 
    DateObj.setDate(DateObj.getDate() + AddDayNumber); 
    document.myform.Date2.value=DateObj.getFullYear() + "-" + (DateObj.getMonth()+1) + "-" + DateObj.getDate(); 

    </script> 
    <script language="VBscript"> 
    sub checknum(my) 
      if Not IsDate(document.myform.Date1.value) then 
        msgbox "请输入日期2009-1-1,OK!" 
        document.myform.Date2.value="" 
      end if 
    end sub 
    </script> 
    <form method="POST" action="xzsl.asp" name="myform"> 
        <TR> 
          <TD height="30" colspan="14" align="left" valign="middle" > <FONT style="LINE-HEIGHT: 100%"> <FONT face=Wingdings color=#99ccff >v </FONT> </FONT> <FONT color=#ff6600>签发时间: 
              <input type="text" name="Date1" size="10" onBlur="zkch()" value="2009-1-1"> 
          </FONT> </TD> 
        </TR> 
      <TR> 
          <TD height="30" colspan="14" align="left" valign="middle" > <FONT style="LINE-HEIGHT: 100%"> <FONT face=Wingdings 
          color=#99ccff >v </FONT> </FONT> <FONT color=#ff6600>有效期: 
              <input type="text" name="Date2"  size="10" readonly style="background-color: #edefef"> 
          </FONT> </TD> 
        </TR> 
        </form> 
    </body> 
    </html> 
      

  2.   

    输入过期日数的话<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    </head> 
    <body> 
    <script language="javascript"> 
    function zkch() 

    var DateObj = new Date(); 
    var AddDayNumber = 30; 
    var Date1=document.myform.Date1.value;
    AddDayNumber = parseInt(Date1,10);
    DateObj.setDate(DateObj.getDate() + AddDayNumber); 
    document.myform.Date2.value=DateObj.getFullYear() + "-" + (DateObj.getMonth()+1) + "-" + DateObj.getDate(); 

    </script> 
    <script language="VBscript"> 
    sub checknum(my) 
      if Not IsNumeric(document.myform.Date1.value) then 
        msgbox "请输入数字,OK!" 
        document.myform.Date2.value="" 
      end if 
    end sub 
    </script> 
    <form method="POST" action="xzsl.asp" name="myform"> 
        <TR> 
          <TD height="30" colspan="14" align="left" valign="middle" > <FONT style="LINE-HEIGHT: 100%"> <FONT face=Wingdings color=#99ccff >v </FONT> </FONT> <FONT color=#ff6600>签发时间: 
              <input type="text" name="Date1" size="10" onkeyup="checknum(this)" onBlur="zkch()" value="0"> 
          </FONT> </TD> 
        </TR> 
      <TR> 
          <TD height="30" colspan="14" align="left" valign="middle" > <FONT style="LINE-HEIGHT: 100%"> <FONT face=Wingdings 
          color=#99ccff >v </FONT> </FONT> <FONT color=#ff6600>有效期: 
              <input type="text" name="Date2"  size="10" readonly style="background-color: #edefef"> 
          </FONT> </TD> 
        </TR> 
        </form> 
    </body> 
    </html>