var start_date = document.getElementById('start_date'); if(start_date.value == ''){ alert('请输入开始日期!'); start_date.focus(); return false; } var end_date = document.getElementById('end_date'); if(end_date.value == ''){ alert('请输入开始日期!'); end_date.focus(); return false; } //日期比较 s1 = start_date.value.replace(/-/g, "/"); s2 = end_date.value.replace(/-/g, "/"); s1 = new Date(s1); s2 = new Date(s2); var days= s1.getTime() - s2.getTime(); var time = parseInt(days / (1000 * 60 * 60 * 24)); if(time>0){ var temp = start_date.value; start_date.value = end_date.value; end_date.value = temp; }