码迷,mamicode.com
首页 > 其他好文 > 详细

my97date 时间范围限制

时间:2017-12-07 15:11:22      阅读:373      评论:0      收藏:0      [点我收藏+]

标签:index   ext   格式   else   his   官方   target   trigger   doc   

需求:根据开始时间,动态限制结束时间

实现:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <select class="sel-settlement-type">
        <option value="1">小时</option>
        <option value="2"></option>
        <option value="3"></option>
    </select>

    <input class="inp-start-date" type="text" onfocus="WdatePicker({dateFmt:‘yyyy-MM-dd HH:mm:00‘})"/>
    <input class="inp-end-date" type="text" onfocus="WdatePicker({dateFmt:‘yyyy-MM-dd HH:mm:00‘, minDate:‘#F{$dp.$D(\‘inp-end-date-min\‘)}‘, maxDate:‘#F{$dp.$D(\‘inp-end-date-max\‘)}‘})"/>
    <input type="hidden" id="inp-end-date-min" value="">
    <input type="hidden" id="inp-end-date-max" value="">

    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script type="text/javascript" src="http://www.my97.net/My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript">
    // 格式化时间
    function formatTime(timestamp, format)
    {
      format    = format || Y-m-d H:i:s;
      
      var oDate = new Date(timestamp);
      var Y     = oDate.getFullYear();
      var m     = oDate.getMonth() + 1;
      var d     = oDate.getDate();
      var H     = oDate.getHours();
      var i     = oDate.getMinutes();
      var s     = oDate.getSeconds();

      return format.replace(Y, Y).replace(m, m).replace(d, d).replace(H, H).replace(i, i).replace(s, s);
    };

    function setTimeLimit()
    {
        $(.sel-settlement-type).on(change, function(){
            if($(.inp-start-date).val()!=""){
                var start = new Date( $(.inp-start-date).val() ).getTime();
            }else{
                var start = new Date().getTime();
            }

            var end_date_min = start + 2 * 3600 * 1000;
            var end_date_max = 0;
            switch($(this).val())
            {
                case 1:
                    end_date_max = start + 1 * 24 * 3600 * 1000;
                    break;
                case 2:
                    end_date_max = start + 7 * 24 * 3600 * 1000;
                    break;
                case 3:
                    end_date_max = start + 30 * 24 * 3600 * 1000;
                    break;
            }

            $(#inp-end-date-min).val( formatTime(end_date_min, Y-m-d H:i:00) );
            $(#inp-end-date-max).val( formatTime(end_date_max, Y-m-d H:i:00) );
        });

        $(.sel-settlement-type).trigger(change);
    }

    setTimeLimit();
    </script>
</body>
</html>

 

官方文档:

http://www.my97.net/demo/resource/2.4.asp#m243

http://www.my97.net/demo/index.htm

 

my97date 时间范围限制

标签:index   ext   格式   else   his   官方   target   trigger   doc   

原文地址:http://www.cnblogs.com/tujia/p/7998742.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!