bootstrap datepicker 时间插件 只显示 特定日期

bootstrap datepicker 时间插件只显示特定日期(该日期从后台返回) 

092344_hcPB_3255899.png

html代码

<title>jQuery UI 日期选择器(Datepicker) - 默认功能</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.9.1.js"></script>
  <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">

<p>日期:<input type="text" id="datepicker"></p>

js代码

<script>
  var availableDates = ["9-3-2017","20-3-2017","20-4-2017","2-4-2017","14-3-2017","15-3-2017"];

function available(date) {
  dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();
  if ($.inArray(dmy, availableDates) != -1) {
    return [true, "","Available"];
  } else {
    return [false,"","unAvailable"];
  }
}
  $(function() {
    $( "#datepicker" ).datepicker({
                 format: "dd/mm/yyyy",
                startDate: "today",
                autoclose: true,
                beforeShowDay:available
    });
  });
  </script>

 

注释:引入的js是网络的,速度估计略微慢,可以改成本地的

可见可选的日期是此处的数组---如需要可以后台返回json再转换

转载于:https://my.oschina.net/u/3255899/blog/849146

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值