jQuery datepicker to prevent past date

后端 未结 15 2829
生来不讨喜
生来不讨喜 2020-12-04 16:34

How do I disable past dates on jQuery datepicker? I looked for options but don\'t seem to find anything that indicates the ability to disable past dates.

UPDATE: Th

相关标签:
15条回答
  • 2020-12-04 17:09

    Try this:

    $("#datepicker").datepicker({ minDate: 0 });
    

    Remove the quotes from 0.

    0 讨论(0)
  • 2020-12-04 17:09

    Remove the quotes surrounding 0 and it will work.

    Working Code Snippet:

    // set minDate to 0 for today's date
    $('#datepicker').datepicker({ minDate: 0 });
    body {
        font-size: 12px; /* just so that it doesn't default to 16px (which is kinda huge) */
    }
    <!-- load jQuery and jQuery UI -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
    
    <!-- load jQuery UI CSS theme -->
    <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
    
    <!-- the datepicker input -->
    <input type='text' id='datepicker' placeholder='Select date' />

    0 讨论(0)
  • 2020-12-04 17:09

    This works:

    $("#datepicker").datepicker({ minDate: +0 });
    
    0 讨论(0)
  • 2020-12-04 17:12

    Use the minDate option to set the minimum possible date. http://jqueryui.com/demos/datepicker/#option-minDate

    0 讨论(0)
  • 2020-12-04 17:14

    I used the min attribute: min="' + (new Date()).toISOString().substring(0,10) + '"

    Here's my code and it worked.

    <input type="date" min="' + (new Date()).toISOString().substring(0,10) + '" id="' + invdateId + '" value="' + d.Invoice.Invoice_Date__c + '"/>
    

    0 讨论(0)
  • 2020-12-04 17:15
    var givenStartDate = $('#startDate').val();
            alert('START DATE'+givenStartDate);
            var givenEndDate = $('#endDate').val();
            alert('END DATE'+givenEndDate);
            var date = new Date();
            var month = date.getMonth()+1;
            var day = date.getDate();
            var currentDate = date.getFullYear() + '-' +
                (month<10 ? '0' : '') + month + '-' +
                (day<10 ? '0' : '') + day;
            if(givenStartDate < currentDate || givenEndDate < currentDate)
             { 
            $("#updateButton").attr("disabled","disabled"); 
             }
             if(givenStartDate < currentDate && givenEndDate > currentDate)
                {
                $("#updateButton").attr("enabled","enabled");
                }
             if(givenStartDate > currentDate || givenEndDate > currentDate) { 
            $("#updateButton").attr("enabled","enabled"); 
             }
    

    Try this. If any mistake, please correct me :) Thanks all.

    0 讨论(0)
提交回复
热议问题