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

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

    According to Bootstrap 4 docs:

    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.

    E.g:

    $('#idOfMyModal').on('shown.bs.modal', function () {
        $('input:first').trigger('focus')
    });
    

    Link.

提交回复
热议问题