欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

layui清空時(shí)間控件后無法使用的解決方法

解決layui時(shí)間控件清空之后無法正常使用的問題,以及時(shí)間范圍的選擇。

網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、成都微信小程序、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了寶塔免費(fèi)建站歡迎大家使用!

共有兩種解決方式:

方式一(layui 1.x):

html代碼:

<div class="layui-inline">
<div class="layui-input-inline">
<input type="text" name="start_time" class="layui-input" id="start_time"
placeholder="開始時(shí)間(修改時(shí)間)">
</div>
</div>
<div class="layui-inline">
<div class="layui-input-inline">
<input type="text" name="end_time" class="layui-input" id="end_time"
placeholder="結(jié)束時(shí)間(修改時(shí)間)">
</div>
</div>

js代碼:

var start = {
istime: true,
format: 'YYYY-MM-DD hh:mm:ss',
max: '2099-06-16 23:59:59',
istoday: true,
choose: function (datas) {
end.min = datas; //開始日選好后,重置結(jié)束日的最小日期
}
};
var end = {
istime: true,
format: 'YYYY-MM-DD hh:mm:ss',
max: '2099-06-16 23:59:59',
istoday: true,
choose: function (datas) {
start.max = datas; //結(jié)束日選好后,重置開始日的最大日期
}
};
document.getElementById('start_time').onclick = function () {
start.elem = this;
laydate(start);
};
document.getElementById('end_time').onclick = function () {
end.elem = this;
laydate(end);
};

方式二(layui 2.x):

html代碼

<div class="layui-inline">
<div class="layui-input-inline">
<input type="text" name="start_time" class="layui-input" id="start_time"
placeholder="開始時(shí)間(修改時(shí)間)">
</div>
</div>
<div class="layui-inline">
<div class="layui-input-inline">
<input type="text" name="end_time" class="layui-input" id="end_time"
placeholder="結(jié)束時(shí)間(修改時(shí)間)">
</div>
</div>

js代碼

layui.use([ 'laydate'], function(){
var $ = layui.$;
var laydate = layui.laydate;
var nowTime = new Date().valueOf();
var max = null;
var start = laydate.render({
elem: '#start_time',
type: 'datetime',
max: nowTime,
btns: ['clear', 'confirm'],
done: function(value, date){
endMax = end.config.max;
end.config.min = date;
end.config.min.month = date.month -1;
}
});
var end = laydate.render({
elem: '#end_time',
type: 'datetime',
max: nowTime,
done: function(value, date){
if($.trim(value) == ''){
var curDate = new Date();
date = {'date': curDate.getDate(), 'month': curDate.getMonth()+1, 'year': curDate.getFullYear()};
}
start.config.max = date;
start.config.max.month = date.month -1;
}
});

根據(jù)開始時(shí)間 動(dòng)態(tài)限制結(jié)束時(shí)間  知識(shí)點(diǎn)

type: 'datetime', 是帶時(shí)分秒的 date 是不帶時(shí)分秒的

layui.use('laydate', function(){
   /* lay('.layui-input').each(function(){
  laydate.render({
    elem: this
    ,trigger: 'click'
    ,change: function(value, date, endDate){
    console.log(value); //得到日期生成的值,如:2017-08-18
    console.log(date); //得到日期時(shí)間對(duì)象:{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
    console.log(endDate); //得結(jié)束的日期時(shí)間對(duì)象,開啟范圍選擇(range: true)才會(huì)返回。對(duì)象成員同上。
    }
  });
});  */
var $ = layui.$;
    var laydate = layui.laydate;
   var nowTime = new Date().valueOf();
    var max = null;
       var start = laydate.render({
        elem: '#start_time',
        type: 'datetime',
        btns: ['clear', 'confirm'],
        done: function(value, date){
            endMax = end.config.max;
            end.config.min = date;
            end.config.min.month = date.month -1;
        },
        change: function(value, date, endDate){
        var timestamp2 = Date.parse(new Date(value));
timestamp2 = timestamp2 / 1000;
            end.config.min = timestamp2;
            end.config.min.month = date.month -1;
    }
    });
    var end = laydate.render({
        elem: '#end_time',
        type: 'date',
        done: function(value, date){
        console.log(" ======  "+date);
            if($.trim(value) == ''){
                var curDate = new Date();
                date = {'date': curDate.getDate(), 'month': curDate.getMonth()+1, 'year': curDate.getFullYear()};
            }
            start.config.max = date;
            start.config.max.month = date.month -1;
        }
    });
});

通過以上代碼,就已經(jīng)可以實(shí)現(xiàn)動(dòng)態(tài)改變開始時(shí)間最大值與結(jié)束時(shí)間最小值的改變了。下面來說一下容易遇到的坑:

坑一 :laydate.render無法重復(fù)渲染,當(dāng)laydate.render對(duì)應(yīng)一個(gè)elem已經(jīng)渲染過一次之后,我們是無法通過再次渲染來修改其中的max值與min值的。

坑二 :startDate.config.max與endDate.config.min是一個(gè)對(duì)象,不是一個(gè)字符串,在網(wǎng)上看到一個(gè)人不負(fù)責(zé)任的給了這么一句話,endDate.config.min="2017-01-01";說可以設(shè)置,我居然信了他的邪掉進(jìn)坑里半天。實(shí)際這里得到的是一個(gè)對(duì)象,不同于在我們渲染時(shí)的min與max了,直接將字符串賦值必然沒有效果。

坑三:dates的格式雖然與endDate.config.min格式相同但是直接讓endDate.config.min=dates你會(huì)發(fā)現(xiàn)并不是你想要的結(jié)果,是因?yàn)殡m然dates中的數(shù)據(jù)是你選擇的日期,可是endDate.config.min中設(shè)置的month的值卻比你輸入的month的值大了一個(gè)月,因此假如你選的開始日期是11月13日,直接賦值給了endDate.config.min之后你會(huì)發(fā)現(xiàn)結(jié)束日期的最小日期變成了12月13日,因此我們需要將dates中的月份值減一后再賦值給endDate.config.min。

以上就是layui時(shí)間控件清空之后無法正常使用的問題的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注創(chuàng)新互聯(lián)其它相關(guān)文章!

當(dāng)前名稱:layui清空時(shí)間控件后無法使用的解決方法
網(wǎng)站地址:http://www.chinadenli.net/article28/joehcp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站做網(wǎng)站小程序開發(fā)網(wǎng)站排名網(wǎng)站導(dǎo)航網(wǎng)站營銷

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)