zoukankan      html  css  js  c++  java
  • MUI中的picker插件怎么设置初始值

    开始时间确定后,选择结束时间需要在开始时间之前。customData的默认值暂时没有修改,修改的有bug

    customData修改:

    var hour = date.getHours();
    var Minute = date.getMinutes();
    var completeHours = new Array([
    {"text":"10:00","value":"10:00"}, {"text":"10:30","value":"10:30"},
    {"text":"11:00","value":"11:00"}, {"text":"11:30","value":"11:30"},
    {"text":"12:00","value":"12:00"}, {"text":"12:30","value":"12:30"},
    {"text":"13:00","value":"13:00"}, {"text":"13:30","value":"13:30"},
    {"text":"14:00","value":"14:00"}, {"text":"14:30","value":"14:30"},
    {"text":"15:00","value":"15:00"}, {"text":"15:30","value":"15:30"},
    {"text":"16:00","value":"16:00"}, {"text":"16:30","value":"16:30"},
    {"text":"17:00","value":"17:00"}]);
    if(Minute==0){
    var completeHoursArr = completeHours[0].slice(2*(hour-10),15);
    }else{ var completeHoursArr = completeHours[0].slice(2*(hour-10)+1,15); }
    options.customData = {"h":completeHoursArr};

    以上有BUG.

    html:

    <div class="mui-input-group" style="">
      <div class="mui-input-row">
        <label>用车时间</label>
         <input type="text" id="orderDateFrom" class="input-rent-datetime mui-text-right" readonly="readonly" placeholder="请选择" data-        options='{"type":"hour","beginYear":2017,"customData":{"h":[
    {"text":"10:00","value":"10:00"}, {"text":"10:30","value":"10:30"},
    {"text":"11:00","value":"11:00"}, {"text":"11:30","value":"11:30"},
    {"text":"12:00","value":"12:00"}, {"text":"12:30","value":"12:30"},
    {"text":"13:00","value":"13:00"}, {"text":"13:30","value":"13:30"},
    {"text":"14:00","value":"14:00"}, {"text":"14:30","value":"14:30"},
    {"text":"15:00","value":"15:00"}, {"text":"15:30","value":"15:30"},
    {"text":"16:00","value":"16:00"}, {"text":"16:30","value":"16:30"},
    {"text":"17:00","value":"17:00"}]},"labels":["年", "月", "日", "时段", "分"]}'>
    </div>
      <div class="mui-input-row">
        <label>还车时间</label>
        <input type="text" id="orderDateTo" class="input-rent-datetime mui-text-right" readonly="readonly" placeholder="请选择"
    data-options='{"type":"hour","beginYear":2017,"customData":{"h":[
    {"text":"10:00","value":"10:00"}, {"text":"10:30","value":"10:30"},
    {"text":"11:00","value":"11:00"}, {"text":"11:30","value":"11:30"},
    {"text":"12:00","value":"12:00"}, {"text":"12:30","value":"12:30"},
    {"text":"13:00","value":"13:00"}, {"text":"13:30","value":"13:30"},
    {"text":"14:00","value":"14:00"}, {"text":"14:30","value":"14:30"},
    {"text":"15:00","value":"15:00"}, {"text":"15:30","value":"15:30"},
    {"text":"16:00","value":"16:00"}, {"text":"16:30","value":"16:30"},
    {"text":"17:00","value":"17:00"}]},"labels":["年", "月", "日", "时段", "分"]}'>
      </div>
    </div>

    js:

    $('.input-rent-datetime').each(function(i, obj) {
      obj.addEventListener('tap', function() {
        var optionsJson = this.getAttribute('data-options') || '{}';
        var options = JSON.parse(optionsJson);
        var picker = new $.DtPicker(options);
        if(obj.getAttribute("id")=="orderDateTo"){
          var date= new Date(beginTime);;
          options.beginYear=date.getFullYear();
          options.beginMonth=date.getMonth()+1;
          options.beginDay=date.getDate();
          options.beginCustomData=date.getHours();
        }
        picker.show(function(rs) {
        obj.value = rs.text;
        picker.dispose();
        beginTime = rs.text;
        });
      }, false);
    });

     方法2

    var date= new Date(beginTime);
    Year = date.getFullYear();
    Month = date.getMonth()+1;
    Day = date.getDate();
    if(Month<10){
    Month = "0"+Month;
    }if(Day<10){
    Day = "0"+Day;
    }
    time=Year+"-"+Month+"-"+Day;
    picker.setSelectedValue(time);

  • 相关阅读:
    消失之物【背包回退】
    数据库连接JDBC
    Spring事物管理机制简单学习
    java生成验证码并可刷新
    spring加载属性配置文件内容
    java读写属性配置文件
    抓取页面图片元素并保存到本机电脑
    java模拟页面表单登录
    通过java进行电脑屏幕截图
    通过JBOSS服务器来实现JMS消息传送
  • 原文地址:https://www.cnblogs.com/Adyblog/p/7126541.html
Copyright © 2011-2022 走看看