Javascript Jquery UI datepicker,点击日期,获取日期并传递给 URL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8912755/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 08:03:44  来源:igfitidea点击:

Jquery UI datepicker, onclick of a date , get the date and pass to URL

javascriptjquerydateuser-interfacedatepicker

提问by Anjana Sharma

I have a jquery UI datepicker calendar in an event page(sharepoint page).

我在事件页面(共享点页面)中有一个 jquery UI 日期选择器日历。

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

I need to get the date once user clicks on any date and get that date and pass it to the page url as mypage.aspx?dt=1/12/2012.I have this but not working.

我需要在用户单击任何日期后获取日期并获取该日期并将其作为 mypage.aspx?dt=1/12/2012 传递给页面 url。我有这个但不工作。

$('.ui-datepicker td a').click(function(){  
        var url=$(location).attr('href');
        var date = $(this.datepicker( "getDate" ));
                if(date != 'null')
            url += '&dt=' + date;           
        window.location.href=url;
        });

Neither is this working..

这也不行..

$('.ui-datepicker td a').click(function() { 
        window.location.href = 'http://mysite/events/Pages/default.aspx?dt=' + $('#datepicker').datepicker().val();
        });

can someone help?

有人可以帮忙吗?

回答by MikeM

try

尝试

$('#datepicker').datepicker({
    onSelect: function(dateText, inst) { 
        window.location = 'http://mysite/events/Pages/default.aspx?dt=' + dateText;
    }
});

uses the onSelectevent (documented here)

使用onSelect事件(记录在此处

Allows you to define your own event when the datepicker is selected. The function receives the selected date as text and the datepicker instance as parameters. this refers to the associated input field.

允许您在选择日期选择器时定义自己的事件。该函数接收所选日期作为文本和日期选择器实例作为参数。这是指相关的输入字段。