簡體   English   中英

Bootstrap-datepicker,getDate不起作用

[英]Bootstrap-datepicker, getDate not working

我試圖弄清楚如何獲取用戶在日期選擇器上選擇的日期。 我已經嘗試了此站點上提到的許多內容,但似乎沒有用。 這是我的代碼:

            // script for the date picker inline
            $('#calendar1 div').datepicker({
                keyboardNavigation: false,
                todayHighlight: true

                $("#calendar1 div").click( 
                var date = $("#calendar1 div").datepicker("getDate");
            });
            });

            // script for the datepicker text input
            $('#calendar2 .input-group.date').datepicker({
                keyboardNavigation: false,
                todayHighlight: true

                $("#calendar2 .input-group.date").click( 
                var date = $("#calendar2 .input-group.date").datepicker("getDate");
            });
            });

當我不運行.click(...)時,日期選擇器似乎很好,所以我相信問題就在那里。

謝謝

您將右花括號放在錯誤的位置,並且處理程序需要為函數,如下所示:

// script for the date picker inline
$('#calendar1 div').datepicker({
    keyboardNavigation: false,
    todayHighlight: true
});

$("#calendar1 div").click(function() {
    // this is the selected element
    var date = $(this).datepicker("getDate");
});

// script for the datepicker text input
$('#calendar2 .input-group.date').datepicker({
    keyboardNavigation: false,
    todayHighlight: true
});

$("#calendar2 .input-group.date").click(function() {
    // this is the selected element
    var date = $(this).datepicker("getDate");
});

我的開始和結束日期如下所示:

<div class="input-daterange dateselector"
                            id="publishedDateSelector">
    <input type="text" class="input-small form-control" /><input
                                type="text" class="input-small form-control" />
</div>

以下代碼初始化日期選擇器:

$('.dateselector').datepicker({
    clearBtn : true,
    orientation : "top",
    todayHighlight : true
});

當我嘗試通過'#publishedDateSelector').datepicker('getDate')獲取日期時,它用來返回不是日期表示形式的jQuery對象。 我約會的方式是:

'#publishedDateSelector input:first').datepicker('getDate'); //StartDate
'#publishedDateSelector input:last').datepicker('getDate');  //EndDate

暫無
暫無

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

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