简体   繁体   English

JQUERY Datepicker周和年

[英]JQUERY Datepicker week and year

I need the datepicker to add the week and year to the url, i currently have it working for the week but i'm unsure how to add a second parameter for the year. 我需要datepicker将星期和年份添加到url中,我目前可以在星期中使用它,但是我不确定如何为年份添加第二个参数。

I need it displayed like this: ?week=10&year=2019 我需要这样显示:?week = 10&year = 2019

Any help is greatly appreciated. 任何帮助是极大的赞赏。

    $(function () {
    $("#datepicker").datepicker({
        onSelect: function(dateText, inst) {
          inst.input.val($.datepicker.iso8601Week(new Date(dateText)));
          window.open(window.location.pathname + '?week=' + this.value, "_self");
        }
    });
});

you can use getFullYear() function of Date 您可以使用Date的getFullYear()函数

 $( function() { $("#datepicker").datepicker({ onSelect: function(dateText, inst) { inst.input.val($.datepicker.iso8601Week(new Date(dateText))); var year=new Date(dateText).getFullYear(); alert(window.location.pathname + '?week=' + this.value +"&year="+year) window.open(window.location.pathname + '?week=' + this.value +"&year="+year + this.value, "_self"); } }); } ); 
 <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>jQuery UI Datepicker - Default functionality</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <link rel="stylesheet" href="/resources/demos/style.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> </head> <body> <p>Date: <input type="text" id="datepicker"></p> </body> </html> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM