使用jQuery UI datepicker进行选择时的日历更改URL [英] Calendar change URL on select with jQuery UI datepicker

查看:89
本文介绍了使用jQuery UI datepicker进行选择时的日历更改URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery UI Picker,我想知道是否有人在选择日期时会自动将其重定向到URL,如下所示:

I am using jQuery UI picker and I am wondering if it's possible when someone pick a date, it automatically redirect them to the URL like so:

index.php?date=2013-10-15

这是我正在使用的插件.

Here's the plug-in I am using.

<script>
    $(function() {
        $( "#datepicker" ).datepicker();
    });
</script>

Date: <input type="text" id="datepicker" />

推荐答案

1)您需要的是 window.location.href ,用于重定向页面.您可以自定义窗口的打开方式.

1) What you need is window.location.href, which is the used to redirect the page. You can customize way the window to opened.

2)一旦在日期选择器(onSelect)中选择了日期,就可以将change事件组合为@ T.J.克劳德在他的答案中说.

2) Once you select the date in datepicker (onSelect), you can combine the change event as @T.J. Crowder said in his answer.

您可以尝试这样

$("#datepicker")
    .datepicker({
      dateFormat: "yy-mm-dd",
      onSelect: function(dateText) {
        $(this).change();
      }
    })
    .change(function() {
      window.location.href = "index.php?date=" + this.value;
    });

这篇关于使用jQuery UI datepicker进行选择时的日历更改URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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