Autofocus input in twitter bootstrap modal

后端 未结 6 963
囚心锁ツ
囚心锁ツ 2020-12-03 09:52

I have such problem - I need to autofocus some element inside twitter bootstrap modal (after it shows). The tricky part is here - content of this modal is loaded using \'dat

6条回答
  •  旧时难觅i
    2020-12-03 10:10

    Above answers are somewhat outdated for latest Bootstrap versions.

    Below is excerpted from: http://getbootstrap.com/javascript/#modals

    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()
    })
    

提交回复
热议问题