datepicker onclose返回未定义值

发布于 2025-01-29 08:32:14 字数 426 浏览 2 评论 0原文

我对jQuery datePicker有一个问题,它总是在Onclose函数中返回一个未定义的值:

<input type="text" class="datepicker">

...


$('.datepicker').datepicker({ 
  format: 'yyyy-mm-dd',
  firstDay: 1,
  minDate: new Date(),
  autoClose: true,
  onClose: function (date, datepicker) {
    alert("Selected Date: " + date);
  }
});

日期总是不确定的 - 但是输入字段正确地填充了日期,例如2022-05-16

我做错了什么?如何获得价值?

输入字段没有ID,因为它是动态创建的。

I have an issue with jquery datepicker in materialize, it always returns an undefined value in the onClose function:

<input type="text" class="datepicker">

...


$('.datepicker').datepicker({ 
  format: 'yyyy-mm-dd',
  firstDay: 1,
  minDate: new Date(),
  autoClose: true,
  onClose: function (date, datepicker) {
    alert("Selected Date: " + date);
  }
});

date is always undefined - but the input field is correctly filled with the date, e.g. 2022-05-16

Did I do something wrong? How can I get the value?

The input field does not have an ID, because it is created dynamically.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我要还你自由 2025-02-05 08:32:14

我复制了您的片段,如您所见,只要您无法复制问题,就不可能进一步帮助您。

$('.datepicker').datepicker({
  format: 'yyyy-mm-dd',
  firstDay: 1,
  minDate: new Date(),
  autoClose: true,
  onClose: function(date, datepicker) {
    alert("Selected Date: " + date);
  }
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.13.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="https://code.jquery.com/ui/1.13.1/jquery-ui.js"></script>

<input type="text" class="datepicker">

I reproduced your snippet, and as you can see it works fine, as long as you are not able to reproduce the issue it will be impossible to help you further.

$('.datepicker').datepicker({
  format: 'yyyy-mm-dd',
  firstDay: 1,
  minDate: new Date(),
  autoClose: true,
  onClose: function(date, datepicker) {
    alert("Selected Date: " + date);
  }
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.13.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="https://code.jquery.com/ui/1.13.1/jquery-ui.js"></script>

<input type="text" class="datepicker">

香橙ぽ 2025-02-05 08:32:14

对我有用:

$('.datepicker').datepicker({ 
  format: 'yyyy-mm-dd',
  firstDay: 1,
  minDate: new Date(),
  autoClose: true,
  onClose: function (date, datepicker) {
    alert("Selected Date: " + date);
  }
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>

<input type="text" class="datepicker">

Works for me:

$('.datepicker').datepicker({ 
  format: 'yyyy-mm-dd',
  firstDay: 1,
  minDate: new Date(),
  autoClose: true,
  onClose: function (date, datepicker) {
    alert("Selected Date: " + date);
  }
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>

<input type="text" class="datepicker">

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文