我有这个代码用于计算两个输入字段之间的日期差异(没有周末),并在第三个文本框中打印天数差异。日期格式是yy-mm-dd(因为mysql)。
<script type="text/javascript">
$("#vazi_od, #vazi_do").change(function() {
var d1 = $("#vazi_od").val();
var d2 = $("#vazi_do").val();
var minutes = 1000*60;
var hours = minutes*60;
var day = hours*24;
var vazi_od1 = getDateFromFormat(d1, "yy-mm-dd");
var vazi_do1 = getDateFromFormat(d2, "yy-mm-dd");
var newvazi_od=new Date();
newvazi_od.setFullYear(vazi_od1.getYear(),vazi_od1.getMonth(),vazi_od1.getDay());
var newvazi_do=new Date();
newvazi_do.setFullYear(vazi_do1.getYear(),vazi_do1.getMonth(),vazi_do1.getDay());
var days = calcBusinessDays(newvazi_od,newvazi_do);
if(days>0)
{ $("#razlika").val(days);}
else
{ $("#razlika").val(0);}
});
</script>
但是,当我选择开始日期和结束日期时,在该字段中没有任何事情发生,应该显示天数的差异......有什么帮助吗?
答案 0 :(得分:1)
您正在使用setFullYear
传递所有日期参数...
setFullYear
仅用于设置日期的年份..
使用
var newvazi_od=new Date(vazi_od1.getYear(),vazi_od1.getMonth(),vazi_od1.getDay());
var var newvazi_do=new Date(vazi_do1.getYear(),vazi_do1.getMonth(),vazi_do1.getDay());
同样要使用getDateFromFormat
和calcBusinessDays
,您需要加入the date library from the javascript toolbox