1

你能告诉我如何阻止在 type="date".in query mobile 中选择未来的日期吗?我在标题上有按钮(+)。点击我打开一个弹出屏幕。有一个日期字段。我需要在日期选择器(type =“date”)中阻止或隐藏未来的日期。

这是小提琴 http://jsfiddle.net/Gajotres/7JqRG/6/

$(document).on('pagebeforeshow', '#Home', function(){ 
    $(document).on( "popupafteropen", "#CaseInformationScreen",function( event, ui ) {
        var now = new Date();

        var day = ("0" + now.getDate()).slice(-2);
        var month = ("0" + (now.getMonth() + 1)).slice(-2);

        var today = now.getFullYear()+"-"+(month)+"-"+(day) ;

        $('#caseDate').val(today);    
    });        
});
4

3 回答 3

1

工作示例:http: //jsfiddle.net/Gajotres/7JqRG/9/

$(document).on('pagebeforeshow', '#Home', function(){ 
    $(document).on( "popupafteropen", "#CaseInformationScreen",function( event, ui ) {
        var now = new Date();

        var day = ("0" + now.getDate()).slice(-2);
        var month = ("0" + (now.getMonth() + 1)).slice(-2);

        var today = now.getFullYear()+"-"+(month)+"-"+(day) ;

        $('#caseDate').attr('max', today);
        $('#caseDate').val(today);    
    });        
});

参考文档:http ://html5doctor.com/html5-forms-input-types/

不幸的是,因为 max 和 min 在 iOS 上不起作用,这里也是一个解决这个问题的 JavaScript:http: //jsfiddle.net/Gajotres/7JqRG/10/

var dateControler = {
    currentDate : null
}

$(document).on('pagebeforeshow', '#Home', function(){ 
    $(document).on( "popupafteropen", "#CaseInformationScreen",function( event, ui ) {
        var now = new Date();

        var day = ("0" + now.getDate()).slice(-2);
        var month = ("0" + (now.getMonth() + 1)).slice(-2);

        var today = now.getFullYear()+"-"+(month)+"-"+(day) ;
        $('#caseDate').val(today);
        dateControler.currentDate = today;
    });        
    $(document).on( "change", "#caseDate",function( event, ui ) {
        var now = new Date();
        var selectedDate = new Date($(this).val());
        if(selectedDate > now) {
            $(this).val(dateControler.currentDate)
        } else {
            dateControler.currentDate = $(this).val();
        }
    });    
});
于 2013-07-19T10:42:54.757 回答
1

我们可以为日期输入类型设置“最大”和“最小”日期,使用属性来隐藏未来日期。

    $('#caseDate').attr("max",today);
    $('#caseDate').attr("min",today);
于 2013-07-19T10:38:51.597 回答
1

我们可以在输入类型中设置 max 和 min 属性,并以 ISO 格式(例如2010-08-14)分配日期,首先是四位数的年份,然后是月份,最后一个位置是月份的日期。

<input type="date" min="2010-08-14" max="2011-08-14" value="2010-08-14"/>

请注意:

  • 月份和日期必须始终使用两位数(例如 01 表示一月,而不仅仅是 1)
  • 它仅适用于Android
于 2017-08-25T09:58:26.493 回答