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

后端 未结 16 1151
感情败类
感情败类 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:48

    I got that bootstrap added the following info on their page:

    Due to how HTML5 defines its semantics, the autofocus HTML attribute has no effect in Bootstrap modals. To achieve the same effect, use some custom JavaScript:

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

    http://getbootstrap.com/javascript/#modals

提交回复
热议问题