Twitter bootstrap - Focus on textarea inside a modal on click

后端 未结 13 728
执笔经年
执笔经年 2020-11-30 22:46

Just starting to play around with bootstrap and it\'s amazing.

I\'m trying to figure this out. I have a textarea for feedback inside a modal window. It works great.

相关标签:
13条回答
  • 2020-11-30 23:39

    I wanted to have a declarative version of this, so I went with the following :

    $(document).ready(function() {
        $(".modal").on('shown.bs.modal', function () {
            $("[data-modalfocus]", this).focus();
        });
    });
    

    You can then simply add a data-modalfocus property to your field, like so :

    <input type="text" data-modalfocus />
    

    And when the modal pops-up, your field will get focus.

    0 讨论(0)
提交回复
热议问题