繁体   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