Bootstrap Modal Focus not working

后端 未结 2 530
梦谈多话
梦谈多话 2021-02-06 00:26

while making a web I didn\'t get focus in a \"input\" into Bootstrap Modal, I tried everything and didn\'t work, modal appears but input doesn\'t get focus. I have make a \"test

相关标签:
2条回答
  • 2021-02-06 00:43

    Try this:

    $('#modal_id').modal('show').on('shown.bs.modal', function() {
        $('input_element_id').focus();
    });
    

    Or Try This:

    $('#modal_id').on('shown.bs.modal', function() {
        $('input_element_id').focus();
    });
    $('#modal_id').modal('show');
    
    0 讨论(0)
  • 2021-02-06 00:52

    Try this (autofocus added to your link):

    <input name="referencia" id="referencia" type="text" class="form-control text-uppercase" placeholder="Descripci&oacute;n" autofocus>
    

    or try this:

    $('#myModal').on('shown.bs.modal', function () {
        $('#myInput').focus();
    })
    

    or this:

    // Every time a modal is shown, if it has an autofocus element, focus on it.
    $('.modal').on('shown.bs.modal', function() {
      $(this).find('[autofocus]').focus();
    });
    
    0 讨论(0)
提交回复
热议问题