我有一个表,其中列周期为from和period to。我想计算期间与期间之间的差异,并在下一栏的总经验中显示。但它在所有行中显示的数据与经验相同。我想在选定日期的每一行中,按时间段和时间段至日期在列经验中显示日期差异,否则显示为空
<script language="JavaScript" type="text/javascript">
function CalculateDiff() {
if($('#datepicker2').val()!="" && $('#datepicker3').val()!=""){
var From_date = new Date($('#datepicker2').val());
var To_date = new Date($('#datepicker3').val());
var diff_date = new Date(To_date - From_date);
var years = Math.floor(diff_date/31536000000);
var months = Math.floor((diff_date % 31536000000)/2628000000);
var days = Math.floor(((diff_date % 31536000000) % 2628000000)/86400000);
var result= years+" year(s)"+ months+" month(s)"+ days+" day(s)";
$("experience").val(result);
}
else{
alert("Please select dates");
return false;
}
}
</script>