开发者

HTML modal popup can lose focus by tabbing to form fields in background

I have modal popup with an overlay written in html / js, everything works fine but if a user tabs enough they can get to th开发者_如何学Ce underlying form fields / buttons. Is there any good way of preventing this?


This is a rough idea but I'm hoping to inspire ideas rather than tell you exactly how to do it. I'll use a combination of pseudocode and pseudo-jquery-code:

function showMymodaldExample() {
    //Show modal dialog (mymodal) code goes here
    //
    //Then we bind an event
    $(document).bind('mymodal.keydown', function(e) {
        if ( currently focussed element is not a child of mymodal ) {
            set the focus previous element
        }
    });
}

And then remember to unbind mymodal.keydown when you destroy/hide the dialog

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜