如何比较两个datepicker日期jquery [英] how to compare two datepicker date jquery
本文介绍了如何比较两个datepicker日期jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码
var $ from = $(#fromDate)。datepicker('getDate') ;
var $ to = $(#toDate)。datepicker('getDate');
if($ from> $ to)
alert(from date from not date to To date);
如果它是同一年的两个日期,它正在工作。否则例如
fromDate ='1/12/2012'(dd / mm / yyyy)toDate = '18 / 6/2013'(dd / mm / yyyy),当你检查条件时,它不起作用。它抛出警报,我给了。
解决方案
我可以建议自动限制日期吗?在此示例中,第二个组合框不允许您选择比您在fisrt one上选择的日期更短的日期。
$(document).ready(function(){
$(#txtFromDate)。datepicker({
numberOfMonths:2,
onSelect:function(selected){
$(#txtToDate)。datepicker(option,minDate,selected)
}
});
$(#txtToDate)。datepicker({
numberOfMonths:2,
onSelect:function(已选中) ){
$(#txtFromDate)。datepicker(option,maxDate,selected)
}
});
});
这是一个工作演示
anyone could you help me guys. this is my code
var $from=$("#fromDate").datepicker('getDate');
var $to =$("#toDate").datepicker('getDate');
if($from>$to)
alert("from date shouldn't greater than To date");
it is working if it is two date same year year. otherwise for example fromDate='1/12/2012'(dd/mm/yyyy) toDate='18/6/2013'(dd/mm/yyyy), while you check condition, it is not working. it throws alert, which i given.
解决方案
Can I suggest auto limiting your dates instead? In this example the 2nd combo box won't allow you to pick a lower date than the one you pick on the fisrt one.
$(document).ready(function(){
$("#txtFromDate").datepicker({
numberOfMonths: 2,
onSelect: function(selected) {
$("#txtToDate").datepicker("option","minDate", selected)
}
});
$("#txtToDate").datepicker({
numberOfMonths: 2,
onSelect: function(selected) {
$("#txtFromDate").datepicker("option","maxDate", selected)
}
});
});
Here is a working demo
这篇关于如何比较两个datepicker日期jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文