简体   繁体   English

是否可以将datepicker / datetimepicker的初始化推迟到输入焦点之前?

[英]Is it possible to defer initialisation of a datepicker/datetimepicker until focus of an input?

I have a screen with a fairly large number of date/time pickers which is struggling with performance (client side) on lower power machines. 我有一个屏幕,其中包含大量的日期/时间选择器,这在低功率机器上的性能(客户端)处于挣扎状态。 I'm wondering if there is a way to defer loading of a date picker until the point at which a user focuses a text input? 我想知道是否有一种方法可以将日期选择器的加载推迟到用户将文本输入聚焦到什么时候?

I'm using this date/time picker: https://github.com/smalot/bootstrap-datetimepicker/ 我正在使用此日期/时间选择器: https : //github.com/smalot/bootstrap-datetimepicker/

At present on page load I initialise the datetimepciker on every input with a class of 'datetimepicker' but this of course results in a significant DOM modification which I believe is causing lower power machines to 'freeze' which rendering the page. 目前,在页面加载时,我使用“ datetimepicker”类初始化每个输入上的datetimepciker,但这当然会导致对DOM的重大修改,我相信这会导致功耗较低的计算机“冻结”从而渲染页面。

UPDATE 更新

Here's what I used in the end to resolve this issue: 这是我最终用来解决此问题的方法:

$('input.datepicker').focus(function(){
    $(this).datetimepicker(pickerOptsGeneral);
    $(this).datetimepicker('show');
    $(this).on('changeDate', function(ev){
        // Do stuff
    }).on('hide', function(){
        $(this).datetimepicker('remove');
    });
});

您可以在文本输入具有焦点时启动日期选择器。

$('input').focus(function(){
// init datepicker
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM