日期联动系统

80酷酷网    80kuku.com

  

在实际开放系统中,我们经常需要查询介于两个日期之间的数据记录。这就用到了日期联动。一般网上有的大都是一个联动很少见两个的。我这里提供两个联动的供大家参考。自己建立一个html文件拷入下面的代码即可。

<html>
<title>销售模糊查询</title><body >
<div align="center"><font color="#0000FF" size="2"><strong>销售查询系统</strong></font>
</div>
<form name="form1" >
    <TABLE cellSpacing=10 cellPadding=0 width=75% align=center border=0>
      <TBODY>
        <TR>
         
        <TD>开始日期(发货)</TD>
          <TD colspan="2"><select name=YYYY >
              <option value="">请选择 年</option>
            </select>
            年
            <select name=MM   >
              <option value="">选择 月</option>
            </select>
            月
            <select name=DD>
              <option value="">选择 日</option>
            </select>
            日 </TD>
        </TR>
        <TR>
         
        <TD>结束日期(发货)</TD>
          <TD colspan="2"><select name=Year >
              <option value="">请选择 年</option>
            </select>
            年
            <select name=Month   >
              <option value="">选择 月</option>
            </select>
            月
            <select name=Day>
              <option value="">选择 日</option>
            </select>
            日 </TD>
        </TR>
        <TR>
          <TD width=93>客户名称</TD>
          <TD colspan="2" > <font color="#FF0000">
            <select name=customname >
              <OPTION selected>全部客户
            </select>
            </font></TD>
        </TR>
        <TR>
          <TD>每页显示数目</TD>
          <TD colspan="2"><select name=pagesize >
              <OPTION selected>10
              <OPTION>20
              <OPTION>50
              <OPTION>100 </select></TD>
        </TR>
        <TR>
          <TD height="23"> </TD>
          <TD width="270"> <div align="center">
              <INPUT class=buttonface type=submit value=确认 name=Submit>
              <INPUT class=buttonface type=reset value=复位 name=Submit2>
            </div></TD>
        </TR>
      </TBODY>
    </TABLE>
    </TD></TR></TBODY></TABLE>
</FORM>
         

<script language="JavaScript"><!--
function YYYYMMDDstart()
{
    MonHead = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

    //先给年下拉框赋内容
    var y   = new Date().getFullYear();
    for (var i = (y-30); i < (y+30); i++) //以今年为准,前30年,后30年
       {
    document.form1.YYYY.options.add(new Option(" "+ i +" ", i));
  document.form1.Year.options.add(new Option(" "+ i +" ", i));
  }

    //赋月份的下拉框
    for (var i = 1; i < 13; i++)
        {
  document.form1.MM.options.add(new Option(" " + i + " ", i));
  document.form1.Month.options.add(new Option(" " + i + " ", i));
  }

    document.form1.YYYY.value = y;
 document.form1.Year.value = y;
    document.form1.MM.value = new Date().getMonth() + 1;
 document.form1.Month.value = new Date().getMonth() + 1;
 
    var n = MonHead[new Date().getMonth()];
    if (new Date().getMonth() ==1 && IsPinYear(YYYYvalue)) n++;
        writeDay(31); //赋日期下拉框Author:meizz
    document.form1.DD.value = new Date().getDate();
 
 
 document.form1.Day.value = new Date().getDate();  //add
 
}
function YYYYDD(str) //年发生变化时日期发生变化(主要是判断闰平年)
{
    var MMvalue = document.form1.MM.options[document.form1.MM.selectedIndex].value;
    if (MMvalue == ""){ var e = document.form1.DD; optionsClear(e); return;}
    var n = MonHead[MMvalue - 1];
    if (MMvalue ==2 && IsPinYear(str)) n++;
       // writeDay(n)

    var MMvalue2 = document.form1.Month.options[document.form1.Month.selectedIndex].value;
    if (MMvalue2 == ""){ var e = document.form1.Day; optionsClear(e); return;}
    var m = MonHead[MMvalue2 - 1];
    if (MMvalue2 ==2 && IsPinYear(str)) m++;
      // writeDay(m)


}
function MMDD(str)  //月发生变化时日期联动
{
    var YYYYvalue = document.form1.YYYY.options[document.form1.YYYY.selectedIndex].value;
    if (YYYYvalue == ""){ var e = document.form1.DD; optionsClear(e); return;}
    var n = MonHead[str - 1];
    if (str ==2 && IsPinYear(YYYYvalue)) n++;
      //  writeDay(n)
 
 
     var YYYYvalue2 = document.form1.Year.options[document.form1.Year.selectedIndex].value;
    if (YYYYvalue2 == ""){ var e = document.form1.Day; optionsClear(e); return;}
    var m = MonHead[str - 1];
    if (str ==2 && IsPinYear(YYYYvalue)) m++;
       //writeDay(m)
}

function writeDay(n)  //据条件写日期的下拉框
{
    var e = document.form1.DD; optionsClear(e);
   for (var i=1; i<(n+1); i++)
        e.options.add(new Option(" "+ i + " ", i));
 
    var ee = document.form1.Day; optionsClear(ee);
   for (var j=1; j<(n+1); j++)
      ee.options.add(new Option(" "+ j + " ", j));
}

function IsPinYear(year)//判断是否闰平年
{   return(0 == year%4 && (year%100 !=0 || year%400 == 0));}
function optionsClear(e)
{
    for (var i=e.options.length; i>0; i--)
        e.remove(i);

}
//--></script>
</body>
</html>

 



分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: