【问题标题】:JQUERY Datepicker week and yearJQUERY Datepicker 星期和年份
【发布时间】:2019-03-07 19:51:11
【问题描述】:

我需要 datepicker 将星期和年份添加到 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");
        }
    });
});

【问题讨论】:

  • 你能做个小提琴吗?

标签: jquery


【解决方案1】:

你可以使用日期的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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-17
    • 2011-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多