Twitter bootstrap - Focus on textarea inside a modal on click

后端 未结 13 796
执笔经年
执笔经年 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 :

    
    

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

提交回复
热议问题