每周JQUERY Datepicker

时间:2019-03-07 11:34:23

标签: jquery

我需要日期选择器将星期和年份添加到url中,我目前可以在星期中使用它,但是我不确定如何为年份添加第二个参数。

我需要这样显示:?week = 10&year = 2019

非常感谢您的帮助。

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

1 个答案:

答案 0 :(得分:1)

您可以使用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>