【问题标题】:jQuery UI Date FormatjQuery UI 日期格式
【发布时间】:2011-12-02 03:22:47
【问题描述】:

我有以下带有 UI Datepicker 的脚本,但我需要将日期作为 URL 中的参数。我似乎无法在 URL 中正确格式化日期。带有日期的输入框是很好,但日期没有显示在我的 URL 字符串中..

我需要将 dateText 变量格式化为“yyyy-mm-dd”

<script type="text/javascript">
    jQuery(function() {
    jQuery('#datepick').datepicker({ dateFormat: "yy-mm-dd" })({
        onSelect: function (dateText, inst) {
        window.location.href="reports?date=" + dateText;
    }
    })
});
</script>

谢谢你..

【问题讨论】:

  • 您目前看到了什么?日期未填写或日期格式错误?
  • 您遇到什么错误?您提供的 JavaScript 不正确。

标签: javascript jquery user-interface datepicker


【解决方案1】:

在你的 onSelect 中试试这个:

window.location.href="reports?date=" + $.datepicker.formatDate("yy-mm-dd", $(this).datepicker("getDate"));

【讨论】:

  • 没问题。如果解决了问题,请点击勾选图标将其标记为已回答,这让我们堆栈溢出的人很高兴:)
  • 与问题相反,这有什么不同?
  • @WilliamNiu 不确定你的意思...?
  • 我相信$.datepicker.formatDate("yy-mm-dd", $(this).datepicker("getDate")) == dateText
猜你喜欢
  • 2016-06-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-28
  • 1970-01-01
  • 1970-01-01
  • 2011-01-30
相关资源
最近更新 更多