【问题标题】:Is there any way to show the jquery datepicker for only a single month有没有办法只显示一个月的 jquery datepicker
【发布时间】:2015-01-01 05:20:51
【问题描述】:

如何显示日期选择器或如何将其限制为仅显示指定月份?只能说 11 月或 2 月。

【问题讨论】:

  • 搜索时发现了什么?
  • 没有找到任何东西@mitchwheat

标签: jquery jquery-ui jquery-plugins jquery-ui-datepicker


【解决方案1】:

您可以使用defaultDate 设置默认月份。 http://jqueryui.com/datepicker/

$(function() {
var d = new Date();
d.setMonth(1);  //Defalt month feburary
$( "#datepicker" ).datepicker({
       defaultDate: d
    });
});

Demo

【讨论】:

  • 太棒了,谢谢。我在想应该有一个 setMonth 和 setYear 方法。但并没有意识到这一点。 :) jsfiddle.net/Superman/tx32r7y7
  • 欢迎。很高兴为您提供帮助。
【解决方案2】:

这里你只能在 JQuery 日期选择器中看到一个月:

以下代码:

<html>
<head>
<meta charset="utf-8">
<title>jQuery UI Datepicker - Default functionality</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
  <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
  <script src="http://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
  <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
<script>
 $(function() {
   $( "#datepicker" ).datepicker();
 });
</script>
</head>
  <body>
    <p>Date: <input type="text" id="datepicker"></p>
  </body>
</html>

在此处显示不同的选项:

http://api.jqueryui.com/datepicker/

【讨论】:

  • 我可以默认看到二月份吗?在另一个例子中,我只想看到八月。
猜你喜欢
  • 2021-02-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-09
  • 1970-01-01
  • 2023-01-20
  • 2022-01-15
  • 2011-07-22
相关资源
最近更新 更多