1. ホーム
  2. javascript

[解決済み] prevent iphone default keyboard when focusing an <input>

2023-06-10 18:58:49

Question

this is how i'm trying

<script type="text/javascript">
     $(document).ready(function(){
        $('#dateIn,#dateOut').click(function(e){
            e.preventDefault();
        }); 
     });
</script>

but the input stills 'launching' iphone's keyboard

ps: i want to do this because i'm using datepicker plugin for date

How to solved?

By adding the attribute readonly (or readonly="readonly" ) to the input field you should prevent anyone typing anything in it, but still be able to launch a click event on it.

This is also usefull in non-mobile devices as you use a date/time picker