jasonxing 发表于 2007-12-8 20:26

[求助] 关于js对日期赋初值的问题

我现在的效果是对第2个日期文本框(todate)点击就赋予系统当前的日期(格式如2007-12-08)
但我想改成只要打开网站就自动赋值,不必去点击,请问我该如何改?
还有就是我想对第1个日期文本框(fromdate)也赋初值,时间为半年前(DateAdd("m",-6,Date())),请
问这又该如何实现?     
谢谢各位帮忙!!!
部分代码如下:


<form name="keyword" method="get" action="search.asp"target='_blank' >

  <tr>
        <td width="31%" height=40 align=right > 發布時間:</td>
        <td width="69%" valign=center ><input name=fromdate readOnly=true class="inputstyle" size=13 value="" >

            <a
            href="javascript:cal1.popup();"><img height=16 alt=點幾選擇日期
            src="images/cal.gif" width=16 border=0></a>  至
            <input name=todate readOnly=true class="inputstyle" size=13 value="" >
   
   <SCRIPT LANGUAGE="JavaScript">
<!--
function getDateString(){
with(new Date()){return getFullYear()+"-"+(getMonth()<9?"0":"")+(getMonth()+1)+"-"+(getDate()<10?"0":"")+getDate();}
}
//-->
</SCRIPT>
            <a
            href="javascript:cal2.popup();"><img height=16 alt=點幾選擇日期
            src="images/cal.gif" width=16 border=0></a>
        <script language=JavaScript>
  var cal1 = new calendar1(document.forms['keyword'].elements['fromdate']);
  cal1.year_scroll = true;
  cal1.time_comp = false;
  var cal2 = new calendar1(document.forms['keyword'].elements['todate']);
  cal2.year_scroll = true;
  cal2.time_comp = false;
                  </script></td>
      </tr></form>

jasonxing 发表于 2007-12-9 11:11

[更正] 关于js对日期赋初值的问题  不好意思代码弄错了,应该是这样

[font=SimSun][size=12pt]不好意思代码弄错了[/size][/font][size=12pt],[/size][font=SimSun][size=12pt]应该是这样[/size][/font][size=12pt],[/size][font=SimSun][size=12pt]不过怎么没人回我啊[/size][/font][size=12pt]?[/size][font=SimSun][size=12pt]请各位高手帮个忙啊[/size][/font][size=12pt]![/size]




[size=12pt][font=SimSun]我现在的效果是对第[/font][font=SimSun]2[/font][font=SimSun]个日期文本框([/font][font=SimSun]todate[/font][font=SimSun])点击就赋予系统当前的日期(格式如[/font][font=SimSun]2007-12-08[/font][font=SimSun])[/font]

[font=SimSun]但我想改成只要打开网站就自动赋值,不必去点击,请问我该如何改?[/font]

[font=SimSun]还有就是我想对第[/font][font=SimSun]1[/font][font=SimSun]个日期文本框([/font][font=SimSun]fromdate[/font][font=SimSun])也赋初值,时间为半年前([/font][font=SimSun]DateAdd("m",-6,Date())[/font][font=SimSun])[/font][font=SimSun],[/font][font=SimSun]请[/font]

[font=SimSun][size=12pt]问这又该如何实现?[/size][/font]



[size=12pt]<form name="keyword" method="get" action="search.asp"target='_blank' >[/size]
[size=12pt]
  <tr>
        <td width="31%" height=40 align=right > 發布時間:</td>[/size]
[size=12pt]        <td width="69%" valign=center ><input name=fromdate readOnly=true class="inputstyle" size=13 value="" > [/size]


[size=12pt]            <a
            href="javascript:cal1.popup();"><img height=16 alt=點幾選擇日期
            src="images/cal.gif" width=16 border=0></a>  至
            <input name=todate readOnly=true class="inputstyle" size=13 value="" >
   
   <SCRIPT LANGUAGE="JavaScript">
<!--
function getDateString(){
with(new Date()){return getFullYear()+"-"+(getMonth()<9?"0":"")+(getMonth()+1)+"-"+(getDate()<10?"0":"")+getDate();}
}
//-->
</SCRIPT>[/size]
[size=12pt]            <a
            href="javascript:cal2.popup();"><img height=16 alt=點幾選擇日期
            src="images/cal.gif" width=16 border=0></a>
        <script language=JavaScript>
  var cal1 = new calendar1(document.forms['keyword'].elements['fromdate']);
  cal1.year_scroll = true;
  cal1.time_comp = false;
  var cal2 = new calendar1(document.forms['keyword'].elements['todate']);
  cal2.year_scroll = true;
  cal2.time_comp = false;
                  </script></td>
      </tr></form>     [/size][/size]

jasonxing 发表于 2007-12-9 12:26

搞定了,自己再定義個函數就搞定了~!

页: [1]

编程论坛