验证开始时间不应大于使用javascript的结束时间

时间:2017-08-21 11:43:28

标签: php jquery html formvalidation-plugin

这是我的HTML代码

<div class="form-group">
    <label for="labeldate" class="col-sm-1 control-label">Time</label>
    <label for="input_fromdate" class="col-sm-2 control-label">From</label>
    <div class="col-sm-3">
        <input type="time" class="form-control" id="from_time" name="from_time" placeholder="Pick here">
    </div>
    <label for="input_todate" class="col-sm-1 control-label">To </label>
    <div class="col-sm-3">
        <input type="time" class="form-control" id="to_time" name="to_time" value="" placeholder="Pick here">
    </div>
</div>

我想确保to_time始终大于from_time。 让我们from_time:05:00 PM and to_time:04:00 PM. 我尝试使用大于jquery但它不能完美地工作。我希望这包含我的jquery验证码

1 个答案:

答案 0 :(得分:0)

我按照您的要求制作了这个简单的Javascript:

var from_time= "11:00 AM";
var to_time = "10:00 PM";

var from = Date.parse('01/01/2011 '+ from_time);
var to = Date.parse('01/01/2011 '+ to_time);

if (from > to){
   console.log ("From greater than To!");
} else {
   console.log ("To greater than from!")
}