js如何将2个日期文本框联动,WdatePicker日期控件

需求如下:

项目截止时间选择后,报账结束时间默认为+3年

 

文本框如下:

 

因为有多个form,第一个sign=0001

 

后面定义了随机数

 

zyBudgetApply.addXinZengXiangMu = function (){

   var sign = parseInt(Math.random()*1000000000+1);

.........................................

}

<tr>
   <th><span style="color: red">*</span>项目起始时间</th>
   <td><input name="projectStartTime"  class="Wdate" οnblur="zyBudgetApply.setTimeStart(this)" style="width:200px;height:30px;" onClick="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd'});"><span style="color:red;display:none;font-weight:bold "></span></td>
   <th><span style="color: red">*</span>项目截止时间</th>
   <td><input name="projectEndTime"  class="Wdate"  οnblur="zyBudgetApply.setTimeEnd(this)" style="width:200px;height:30px;" onClick="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd',onpicked:function(){formatEndTime('0001')}});" ><span style="color:red;display:none;font-weight:bold "></span></td>
</tr>
<tr>
   <th><span style="color: red">*</span>报账起始时间</th>
   <td><input name="reimburseStartTime"  class="Wdate" οnblur="zyBudgetApply.setReimburseTimeStart(this)" style="width:200px;height:30px;" onClick="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd'});"><span style="color:red;display:none;font-weight:bold "></span></td>
   <th><span style="color: red">*</span>报账截止时间</th>
   <td><input name="reimburseEndTime"  class="Wdate"  οnblur="zyBudgetApply.setReimburseTimeEnd(this)" style="width:200px;height:30px;" onClick="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd'});" value=""><span style="color:red;display:none;font-weight:bold "></span></td>
</tr>

 

 

js:

function dateFormat(date){
   var year = date.getFullYear();//获取完整的年份(4位,1970-????)
   var month = date.getMonth() + 1;//获取当前月份(0-11,0代表1月)
   var day = date.getDate();//获取当前日(1-31)
   if(month < 10){
      month = "0" + month;
   }
   if(day < 10){
      day = "0" + day;
   }
   return year + "-" + month + "-" + day;
}

 

 

//默认为项目截止时间延长三年
function formatEndTime(sign) {
   console.log(sign);
   debugger;
   var dateStr = $dp.cal.getDateStr();//控件自带方法
   var date = new Date(dateStr);
   date.setFullYear(date.getFullYear()+3);
   $("#xinZengXiangMuOne_form"+sign+" [name=reimburseEndTime]").val(dateFormat(date));
}

 

 

 

 

 


版权声明:本文为qq_40987844原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。