layui時間控件閃退問題

記錄layui laydata控件閃退的問題

問題描述:點擊input框時,時間選擇框會出現閃退的情況

#問題分析:經查看發現實際上是時間彈窗自身計算了當前瀏覽器的可用高度,當高度不足以顯示時間選擇框時,則會自動偏移,導致鼠標可以點擊到時間選擇框,從而導致input框失去焦點、時間選擇框隱藏。最終結合layui官方文檔最終解決;

主要原因是時間控件函數裏沒有添加trigger: 'click',就會導致黨時間控件靠近瀏覽器窗口邊緣的時候,時間控件沒有找到合適位置打開日期彈框。防止頁面被縮小查看,建議都寫
    <input class="layui-input" placeholder="查詢日期" id="id" name="checkDate">
    
    <script>
      layui.use(['form','laydate'],function(){
    laydate.render({
            elem:'#id'
            ,format:'yyyy-MM-dd'
            ,max:'2099-06-16'
            ,min:'1980-01-01'
        });
    });
    </script>
  

<input type="text" class="layui-input test-item" placeholder="審覈時間" value="${model.checkDate}" name="checkDate">    

<script>
layui.use('laydate', function(){
    var laydate = layui.laydate;
    //同時綁定多個
    lay('.test-item').each(function(){
        laydate.render({
            elem: this
            ,format:'yyyy-MM-dd HH:mm:ss'
            ,type:'datetime'
            ,trigger: 'click'//主要是沒寫這個事件觸發方法
        });
    });
});

</script>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章