Jquery UI datepicker,单击日期,获取日期并传递到URL

时间:2022-11-30 09:08:50

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

我在事件页面(sharepoint页面)中有一个jquery UI datepicker日历。

$('#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?

有人可以帮忙吗?

1 个解决方案

#1


28  

try

试一试

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

uses the onSelect event (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.

允许您在选择datepicker时定义自己的事件。函数以文本形式接收选定的日期,以参数形式接收datepicker实例。这是指关联的输入字段。

#1


28  

try

试一试

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

uses the onSelect event (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.

允许您在选择datepicker时定义自己的事件。函数以文本形式接收选定的日期,以参数形式接收datepicker实例。这是指关联的输入字段。