简体   繁体   English

jQuery - Datepicker 在第一次加载时没有拉起?

[英]jQuery - Datepicker not pulling up on first load?

I have this page and this page that i have datepickers on them using the jquery ui datepicker.我有这个页面和这个页面,我有使用 jquery ui datepicker 的日期选择器。 It works well sometimes but when i first click on the field on occasions nothing happens at all.有时效果很好,但是当我第一次单击该字段时,有时什么也没有发生。 Cant seem to figure out why.似乎无法弄清楚为什么。 Here is my code这是我的代码

My html我的 html

<input type="text" value="" size="30" name="report[start_date]" id="report_start_date" autocomplete="off" class="hasDatepicker">

jQuery jQuery

$('#report_end_date').datepicker();

$('#report_start_date').datepicker();

The code is simple enough but its not making sense...any ideas代码很简单,但没有意义......任何想法

At the bottom of your page you have在您的页面底部,您有

document.getElementById('report_start_date').focus();

This focuses the element, but does not trigger the datepicker.这会聚焦元素,但不会触发日期选择器。 You have to manually click it.您必须手动单击它。

Try it, click away to unfocus, then click to refocus and it'll work.试试看,单击离开以取消焦点,然后单击以重新聚焦,它会起作用。

To trigger the datepicker programmatically, use this:要以编程方式触发日期选择器,请使用以下命令:

$('#report_start_date').datepicker('show');

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

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