我想将开始日期和结束日期与基础日期选择器进行比较。
我的比较是:
if(enddate < startdate){
error
}
这里是我的代码:
jQuery("#startDate,#endDate").fdatepicker({
autoclose: true,
format: "dd.mm.yyyy",
language: 'de',
todayHighlight: true
});
var startdate = "";
var enddate = "";
jQuery("#startDate").change(function() {
startdate = jQuery('#startDate').val();
console.log(startdate);
});
jQuery("#endDate").change(function() {
enddate = jQuery('#endDate').val();
console.log(enddate);
});
// compare
if(enddate < startdate){
console.log("error");
}
这是我的jsfiddle example
答案 0 :(得分:0)
这里有更新的代码,以显示我的意思
<强> HTML 强>
<div class="form-row field_text">
<label for="startdaum" class="required">Start Date *:</label><br>
<input type="text" id="startDate" name="startdatum" class="input_text date">
</div>
<div class="form-row field_text ">
<label for="enddatum" class="required" id="">End Date *:</label><br>
<input type="text" id="endDate" name="enddatum" class="input_text">
</div>
<div class="form-row field_text">
<label for="interval" class="required">interval:</label><br>
<div class="select-box">
<select class="" name="interval" id="intervall" >
<option value="0">no </option>
<option value="1">all da</option>
<option value="7">weekly</option>
<option value="14">all 2 weeks</option>
</select>
</div>
</div>
<input type="submit" value="Submit" />
<强> JS 强>
jQuery("#startDate,#endDate").fdatepicker({
autoclose: true,
format: "dd.mm.yyyy",
language: 'de',
todayHighlight: true
});
var startdate = "";
var enddate = "";
jQuery("#startDate").change(function() {
startdate = jQuery('#startDate').val();
console.log(startdate);
});
jQuery("#endDate").change(function() {
enddate = jQuery('#endDate').val();
console.log(enddate);
});
// compare
jQuery('input[type=submit]').on('click', function () {
startdate = process(startdate);
enddate = process(enddate);
console.log(startdate);
console.log(enddate);
if(enddate < startdate){
console.log("error");
}
});
function process(date){
var parts = date.split(".");
return new Date(parts[2], parts[1] - 1, parts[0]);
}
这是一个有效的JSFIDDLE DEMO