简体   繁体   English

在输入字段下方显示日期选择器

[英]Display date picker below input field

I am using bootstrap datepicker when I click on input field calendar display above the input field.当我单击输入字段上方的输入字段日历显示时,我正在使用引导程序日期选择器。 I want to display it bellow input field.我想在输入字段下方显示它。

JS JS

$(function () {
        $("#fFYear").datepicker({
            dateFormat: "mm/dd/yy",
            showOtherMonths: true,
            selectOtherMonths: true,
            autoclose: true,
            changeMonth: true,
            changeYear: true,
            //gotoCurrent: true,
        }).datepicker("setDate", new Date());
        //alert("#FirstFiscalTo");

    });

Input Field输入字段

<input class="textboxCO input-sm form-control datePickerPickcer" id="fiscalYear" name="FiscalYear" type="text" value="6/30/2015 7:12:21 AM">

Lücks solution is the one, just one minor detail dateFormat option is not valid, is format as referenced in the official doc here .卢克斯解决方案是一个,只是一个小细节dateFormat选项是无效的,是format在官方文档中引用在这里 You are not noticing this error because "mm/dd/yy" is the default format.您没有注意到此错误,因为"mm/dd/yy"是默认格式。

So, te solution will look like:因此,te 解决方案将如下所示:

$(function () {
    $("#fiscalYear").datepicker({ //<-- yea .. the id was not right
        format: "mm/dd/yy", // <-- format, not dateFormat
        showOtherMonths: true,
        selectOtherMonths: true,
        autoclose: true,
        changeMonth: true,
        changeYear: true,
        //gotoCurrent: true,
       orientation: "top" // <-- and add this
    });
});
$(function () {
        $("#fiscalYear").datepicker({
            dateFormat: "mm/dd/yy",
            showOtherMonths: true,
            selectOtherMonths: true,
            autoclose: true,
            changeMonth: true,
            changeYear: true,
            //gotoCurrent: true,
           orientation: "top" // add this
        });
});

Reference: https://bootstrap-datepicker.readthedocs.org/en/latest/options.html#orientation参考: https : //bootstrap-datepicker.readthedocs.org/en/latest/options.html#orientation

$("#fFYear").datepicker({
    dateFormat: "mm/dd/yy",
    showOtherMonths: true,
    selectOtherMonths: true,
    autoclose: true,
    changeMonth: true,
    changeYear: true,
    orientation: "bottom left" // left bottom of the input field
});

For datepicker from jquery rather than bootstrap, option [orientation] is not available.对于来自 jquery 而不是 bootstrap 的日期选择器,选项 [orientation] 不可用。 The positioning of the datepicker panel is auto set by jquery depending on the cursor position relative to the window.日期选择器面板的位置由 jquery 自动设置,具体取决于相对于窗口的光标位置。

To ensure that datepicker is always below the cursor position when an input field is selected, I used the below code为了确保在选择输入字段时日期选择器始终低于光标位置,我使用了以下代码

$("input").datepicker().click(function(e){
  $('.ui-datepicker').css('top', e.pageY);
})

e.pageY is the current mouse Y axis position in window. e.pageY 是当前鼠标在窗口中的 Y 轴位置。 as class ui-datepicker position is absolute, when "top" attribute is set to cursor Y axis value, the datepicker ui panel will be displayed always below cursor.由于类 ui-datepicker 位置是绝对的,当“top”属性设置为光标 Y 轴值时,日期选择器 ui 面板将始终显示在光标下方。

 $(function () { $("#fiscalYear").datepicker({ dateFormat: "mm/dd/yy", showOtherMonths: true, selectOtherMonths: true, autoclose: true, changeMonth: true, changeYear: true, //gotoCurrent: true, }); });
 <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="https://code.jquery.com/jquery-1.10.2.js"></script> <script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <input id="fiscalYear" name="FiscalYear" type="text" value="6/30/2015 7:12:21 AM">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM