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

前端 未结 11 1709
野性不改
野性不改 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 14:00

    Instead of disabling the input give it a "readonly" property. This is better then disabling it because you can save the form without changing it.

    Here is more info about readonly.

    0 讨论(0)
  • 2020-12-02 14:02

    Using the latest version of the DatePicker, it's possible to do it like this:

    //for tablets / phones
        $('#yourElement').datepicker().on('show', function (e) {
            $(this).trigger('blur');
        })
    

    Please note however, the keyboard may flash at the bottom of the screen for a second until the blur() is enacted.

    0 讨论(0)
  • 2020-12-02 14:04

    That's how I managed to deal with this problem by making the browser think the user blured the input so it hides the keyboard before it has time to show :

    $('blabla')
        .datepicker(
        {
            /* options */
        })
        .on('focus',function()
        {
            $(this).trigger('blur');
        });
    

    Works well for me where many of the other solutions I found didn't !

    0 讨论(0)
  • 2020-12-02 14:05

    I used a slightly modified version of Rob Osborne's solution and it successfully prevented the keyboard from popping up on the iPad and iPhone.

    $(".datePicker").datepicker({
        showOn: 'button',
        onClose: function(dateText, inst) 
        { 
            $(this).attr("disabled", false);
        },
        beforeShow: function(input, inst) 
        {
            $(this).attr("disabled", true);
        }
    });
    
    0 讨论(0)
  • 2020-12-02 14:07

    I have used this code and it works great... ".hasDatepicker" class is for my input that hold the date picker

    <script type="text/javascript">
    

    jQuery( document ).ready(function() {

    var ybdDatePick = jQuery( ".hasDatepicker" );
    
        jQuery(function() {
           ybdDatePick.datepicker({ }).attr('readonly','readonly');
    
           ybdDatePick.on('focus',function() {
                jQuery(this).trigger('blur');
                 this.datepicker({ }).attr('readonly','readonly');
    
              }
            );
    
    });
    });
    

    0 讨论(0)
提交回复
热议问题