How to Set focus to first text input in a bootstrap modal after shown

后端 未结 16 1127
感情败类
感情败类 2020-12-07 15:12

I load a dynamic bootstrap modal and it contains few text inputs. The issue i face that i want the cursor to focus on the first input in this modal, and this is not happenin

16条回答
  •  南方客
    南方客 (楼主)
    2020-12-07 15:54

    The usual code (below) does not work for me:

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

    I found the solution:

    $('body').on('shown.bs.modal', '#myModal', function () {
        $('input:visible:enabled:first', this).focus();
    })
    

    see more here

提交回复
热议问题