如何将jQuery UI datepicker初始化为查询字符串中的日期? [英] How do I initialize a jQuery UI datepicker to a date from the querystring?

查看:54
本文介绍了如何将jQuery UI datepicker初始化为查询字符串中的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出此标记:

// Calendar.html?date=1/2/2003
<script>
  $(function() { 
    $('.inlinedatepicker').datepicker();
  });
</script>
...

<div class="inlinedatepicker" id="calendar"/>

这将显示一个行内日期选择器,只需很少的力气(太棒了!).如何将日期选择器预设为通过查询字符串传递的日期?

This will display an inline datepicker with very little effort (awesome!). How do I preset the datepicker to the date passed in via the query string?

请注意,在这种情况下,我没有输入框-仅将日历附加到div.

Note that in this case, I don't have an input box--just a calendar attached to a div.

推荐答案

这应该可行,尽管您可能会遇到语言环境问题(特别是M/D/Y与D/M/Y).

This should work, though you may run into locale issues (specifically, M/D/Y vs. D/M/Y).

var date = location.match(/(?:\?|&)date=(\d+\/\d+\/\d+)(&|$)/)[1];
$('.inlinedatepicker').datepicker().datepicker("setDate", new Date(date));

这篇关于如何将jQuery UI datepicker初始化为查询字符串中的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆