Javascript 在输入字段下方显示日期选择器
当我单击输入字段上方的输入字段日历显示时,我正在使用引导日期选择器。我想在输入字段下面显示它 JSJavascript 在输入字段下方显示日期选择器,javascript,jquery,twitter-bootstrap,datepicker,Javascript,Jquery,Twitter Bootstrap,Datepicker,当我单击输入字段上方的输入字段日历显示时,我正在使用引导日期选择器。我想在输入字段下面显示它 JS $(function () { $("#fFYear").datepicker({ dateFormat: "mm/dd/yy", showOtherMonths: true, selectOtherMonths: true, autoclose: true, c
$(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 class="textboxCO input-sm form-control datePickerPickcer" id="fiscalYear" name="FiscalYear" type="text" value="6/30/2015 7:12:21 AM">
$(函数(){
美元(“#财政年度”)。日期选择器({
日期格式:“mm/dd/yy”,
showOtherMonths:是的,
选择OtherMonths:true,
自动关闭:是的,
变化月:对,
变化年:是的,
//gotoCurrent:是的,
});
});代码>
参考资料:Lücks解决方案是唯一的解决方案,只有一个次要细节dateFormat
选项无效,是官方文件中引用的format
。您没有注意到此错误,因为默认格式为“mm/dd/yy”
因此,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
});
});
$(函数(){
$(“#fiscalYear”).datepicker({/对于来自jquery而非引导的datepicker,选项[orientation]不可用。
日期选择器面板的位置由jquery根据光标相对于窗口的位置自动设置
为了确保在选择输入字段时datepicker始终位于光标位置下方,我使用了下面的代码
$("input").datepicker().click(function(e){
$('.ui-datepicker').css('top', e.pageY);
})
e、 pageY是窗口中鼠标Y轴的当前位置。
当“顶部”时,类ui日期选择器的位置是绝对的属性设置为光标Y轴值,则日期选择器ui面板将始终显示在光标下方。请提供一个提琴,或者您可以尝试使用日期选择器父元素的position:relative
css。这就是您要找的吗?请在stackoverflow.com/a/46175560/7250028上查看我的答案“>链接。你会得到正确的方向。这正是我想要的。。谢谢!!:)这段代码中的具体内容解决了这个问题吗?仅代码的答案在Stackoverflow上的价值很低,因为它们对未来数千名研究人员的教育/授权作用甚微。
$("#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
});
$("input").datepicker().click(function(e){
$('.ui-datepicker').css('top', e.pageY);
})