簡體   English   中英

如何在jQuery DatePicker(Wordpress)中禁用今天的日期

[英]How to disable today's date in jQuery DatePicker (Wordpress)

我目前正在使用名為Flexible Checkout Fields Pro的插件。 我想調整日期選擇器上的設置。 我們公司根據訂單向住在酒店和游輪上的游客送貨。 唯一的事情是我們很少在下訂單的同一天而不是在周末交貨。 我與開發人員聯系,並獲得了本指南的指導, 網址為: http : //www.spiceforms.com/blog/how-to-disable-dates-in-jquery-datepicker-a-short-guide/

在這里,它為我提供了“ noWeekends”的編碼:

$(function() {
    $( "#datepicker" ).datepicker({
        beforeShowDay: $.datepicker.noWeekends
    });
});

我不知道在WordPress目錄中的哪里插入此代碼,而且我仍然不知道如何在時間選擇器上禁用當前日期...任何幫助將不勝感激。

您可以將以下內容粘貼到頁腳中,它應該可以工作。 否則,您可以刪除<script></script>標記並將其粘貼到外部JS文件中,只要在加載插件后調用它即可。

讓我為您分解一下:

閱讀整個代碼中的注釋

<script>

// First we have to enable the jQuery '$' selector in WP.
(function($) {

/** Days to be disabled as an array */
var disableddates = [];

function DisableSpecificDates(date) {

    // Get the current date values
    var m = date.getMonth(); // Month
    var d = date.getDate(); // Day
    var y = date.getFullYear(); // Year

    // Convert the date in to the mm-dd-yyyy format
    var currentdate = m + '-' + d + '-' + y ;

    // Add the current date to the disableddates array
    disableddates.push(currentdate);

    // We will now check if the date belongs to disableddates array
    for (var i = 0; i < disableddates.length; i++) {

        // Now check if the current date is in disabled dates array.
        if ($.inArray(currentdate, disableddates) != -1 ) {
            return [false];
        }
    }

    // In case the date is not present in disabled array, we will now check if it is a weekend.
    // We will use the noWeekends function
    var weekenddate = $.datepicker.noWeekends(date);
    return weekenddate;

}

// Initialize the datepicker function and call the 'DisableSpecificDates' as the 'beforeShowDay' callback.
$( "#datepicker" ).datepicker({
    beforeShowDay: DisableSpecificDates
});

})(jQuery); // Close out WP jQuery.
</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM