时间文本框,入职时间,工龄的换算
入职时间:
在职工龄:
离职日期:
<div class="popTxt L control"><span class="popStit">入职时间:</span><input id="StartDate" class="inputText Wdate inWkTime" type="text" name="entrytime" value="" /></div> <div class="popTxt L control"><span class="popStit">在职工龄:</span><input class="inputText wkAge" type="text" name="lenofservice" value="2年零4个月" disabled="disabled" /></div> <div class="popTxt L control"><span class="popStit">离职日期:</span><input class="inputText Wdate outWoke" type="text" name="quittime" value="" /></div>
function inWokeTime(thisVal,dataTime){ if(thisVal&&dataTime){ var oldTime=thisVal.split("-"); var newTime=dataTime.split("-"); var cYear=newTime[0]-oldTime[0]; var cMonth=newTime[1]-oldTime[1]; $(".wkAge").val(""); if (cYear==0) { if (cMonth <= 0) { $(".wkAge").val("入职时间不足一个月"); } else { $(".wkAge").val(cMonth.toString()+"个月"); } } else if (cYear > 0) { if (cMonth <= 0) { if(cYear<2){ $(".wkAge").val((12+cMonth).toString()+"个月"); } else{ $(".wkAge").val((cYear-1).toString()+"年零"+(12+cMonth).toString()+"个月"); } } else { $(".wkAge").val(cYear.toString()+"年零"+cMonth.toString()+"个月"); } } } } function setWokeTime(newData,oldData){ var mydate = new Date(); var year = mydate.getFullYear(), month = (mydate.getMonth()+1)>9?mydate.getMonth()+1:"0"+(mydate.getMonth()+1), date = mydate.getDate()>9?mydate.getDate():"0"+(mydate.getDate()); var dataTime = year+ "-"+ month + "-"+ date; if(newData==""){ inWokeTime(oldData,dataTime); } else{ inWokeTime(oldData,newData); } }
$(function () { setWokeTime($(".outWoke").val(),$(".inWkTime").val()); $(".inWkTime").blur(function(){ setWokeTime($(".outWoke").val(),$(this).val()); }); $(".outWoke").blur(function(){ setWokeTime($(this).val(),$(".inWkTime").val()); }); });