Datepicker jQuery在IE 7中不起作用

时间:2014-07-10 07:40:58

标签: javascript jquery jquery-ui-datepicker

我正在使用此代码:

<script type="text/javascript">
$(document).ready(function () { 
var selector = function (dateStr) {
        var d1 = $('.fromdate').datepicker('getDate');
        var d2 = $('.todate').datepicker('getDate');
        $('.fromdate').datepicker("option", "maxDate",d2);           
        $('.todate').datepicker("option", "minDate",d1);  
        var diff = 1;
        if (d1 && d2) {
            diff = diff + Math.ceil((d2.getTime() - d1.getTime()) / 86400000);
        }
        $('.calculated').val(diff);
        $('.minim').val(d1)
    }
$('.fromdate').datepicker({
  showOn: "button",
  buttonImage: "images/calendar_year.png",
  buttonImageOnly: true,
                dateFormat : 'yy-mm-dd',
                changeMonth: true,
                changeYear: true,
                minDate: 0
});
$('.todate').datepicker({ 
    showOn: "button",
    buttonImage: "images/calendar_year.png",
    buttonImageOnly: true,
                dateFormat : 'yy-mm-dd',
                changeMonth: true,
                changeYear: true,
                minDate: ($(".fromdate").is(":visible") && $(".todate").html() != ""? $('.todate').datepicker('getDate'): 'null'),
});
$('.fromdate,.todate').change(selector)
});
</script>

它工作得很好但昨天我接到一个人的电话说它在IE 7中不起作用。我发现了两个症状: - 任何参数都会使日历不显示。它只能像这样工作

$('.fromdate').datepicker({
});

谢谢!

1 个答案:

答案 0 :(得分:1)

试试这个:使用索引0作为minDate值的所有类选择器,因为它返回数组。并删除最后一个逗号。

$('.todate').datepicker({ 
    showOn: "button",
    buttonImage: "images/calendar_year.png",
    buttonImageOnly: true,
                dateFormat : 'yy-mm-dd',
                changeMonth: true,
                changeYear: true,
                minDate: ($(".fromdate:first").is(":visible") && $(".todate:first").html() != ""? $('.todate:first').datepicker('getDate'): 'null')

});