Bootstrap Modal Focus not working

后端 未结 2 532
梦谈多话
梦谈多话 2021-02-06 00:26

while making a web I didn\'t get focus in a \"input\" into Bootstrap Modal, I tried everything and didn\'t work, modal appears but input doesn\'t get focus. I have make a \"test

2条回答
  •  野的像风
    2021-02-06 00:52

    Try this (autofocus added to your link):

    
    

    or try this:

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

    or this:

    // Every time a modal is shown, if it has an autofocus element, focus on it.
    $('.modal').on('shown.bs.modal', function() {
      $(this).find('[autofocus]').focus();
    });
    

提交回复
热议问题