Ci Kai
Ci Kai

Reputation: 335

Why jquery.focus() doesn't work on my bootstrap popup modal?

I use require.js. jquery.focus() works on normal html site but doesn't work on bootstrap popup modal. I make a search form which contains this textbox.

define(["common"], function(common) {
    function init() {
        initFocus();
    }

    function initFocus() {
        $("#p001SearchIDTxt").focus();
    }

    return {
        "init": init
    }
});

Upvotes: 1

Views: 1675

Answers (1)

Nere
Nere

Reputation: 4097

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 () {
    $("#p001SearchIDTxt").focus();
})

Source: http://v4-alpha.getbootstrap.com/components/modal/

Upvotes: 4

Related Questions