ipad web application: How do I prevent the keyboard from popping up on jquery datepicker

前端 未结 11 1750
野性不改
野性不改 2020-12-02 13:42

I have a form with an date field with a jquery datepicker attached to it.

When I select the date field the datepicker pops up but then the iPad keyboard slides into

11条回答
  •  没有蜡笔的小新
    2020-12-02 13:54

    I believe this solution could work for all different date time pickers, but I have only tested it with the date picker from XDSoft.

    The idea is to disable mouse events (pointer-events: 'none') on the input element so that the keyboard won't appear, and then add a onclick event on a parent div that wraps around the input element. The onclick event should then open the date time picker.

    Code Example

    This demonstrates how to fix the issue when using XDSoft's datetimepicker.

    The solution assumes that the input element is wrapped inside a div element.

    (function($){
        var originalDateTimePicker = $.fn.datetimepicker;
        $.fn.datetimepicker = function(args){
            this.each(function(i, dateTimePicker){
                dateTimePicker = $(dateTimePicker);
                dateTimePicker.closest('div').on('click', function(e){ 
                    dateTimePicker.trigger('open');
                });
                dateTimePicker.css({ 'pointer-events': 'none' });
            });
            return originalDateTimePicker.apply(this, arguments);
        };
    })(window.jQuery||window.$);
    

提交回复
热议问题